strange linker situation
It happened to me the following strange thing:
I had a function1_1() in file1.c called by another routine in file2.c
without it being declared extern inside file2.c (or any included header)
Strangely enough the linker gave no error
Plus I had another function still in file1.c function1_2() exactly the same as function1_1() with the only difference that this time I had
If I a substitute (inside file2.c) the call of function1_1() with a call to function1_2() the program runs correctly
while if I substitute the call of function1_2() with a call to function1_1() the program has an incorrect behaviour and i think i tested some memory areas erroneously overwritten (don't remember but guess some stack variables of function1_1() )
Could you suggest an explanation??
In C, if a function is called without being previously declared, the compiler assumes it is a function that accepts an arbitrary set of arguments and returns int (effectively the function as called is implicitly declared). This causes strange behaviours if the actual function (eg as implemented in another source file) does not match what the compiler assumes.
The latest C standard has either deprecated or removed (I can't remember which offhand) this "feature". But older compilers will support it - and recent compilers might.
C functions are all implicitly extern, unless you declare them static. Just an observation. If it's an included header, it's an included header, right?
Originally Posted by mynickmynick