When we want to use a function say void foo(void)
in File1.c
in my Main.c
[ where my main function is ] - why do i not need to write:
extern int main(void);
In File1.c
?
Assuming
File1.c
andMain.c
are in a Single TU.
You never need to write extern
with function declarations. Functions have external linkage by default. There's a strange unexplainable habit observed in some older code: to add extern
to all external function declarations. (This is probably what led to your question about main
.) In reality, it is completely unnecessary, serves no purpose and only clutters the code.
You can surely declare main
with extern
, if you so desire. But it is totally redundant.
For a start, functions are extern
by default.
Furthermore, main
is "special"; the linker treats it differently.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With