I have a program that #includes a number of header files. However, these header files merely contains #ifndef, #define and #endif and nothing else. This program calls a number of functions which are defined in other source files. How is it possible for the program to work when the header files did not include any declarations of the functions which are defined in those source files? The program works, however, I'm interested in finding out why the program could works. Thanks!
#include header_file
Collapse
X
-
Originally posted by oler1sTwo questions:
Was this C code? And second, if so, I assume it was not compiled with all warnings turned on?
The program is written in C. It has quite a number of header files and they are nested as well. Is it possible for the compiler to report no error in such instances?Comment
-
Not that I know of.
Functions have to be identified as functions before you call them.
The only thing I can think of is that some nitwit is including the source file that copntains the function code. Do you see any #include that are for .c files or other files that contain code??Comment
-
In C, you can actually compile code without declaring the function. The compiler will silently assume it to return an int, unless of course, you turned on warnings.
If the function doesn't return an int, this may be disastrous. Which is why in C it's recommended you don't cast malloc. If you forget stdlib.h, well, at runtime it definitely won't be working properly.
(Obviously, do not take my remarks as a sign that you should ever rely on the default assumption. Always declare the function before using it.)Comment
-
I am always heartened by comments such as yours that abandoning C for a real language, like C++, was a good idea.Comment
Comment