#include header_file

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • TKM
    New Member
    • Dec 2007
    • 11

    #include header_file

    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!
  • oler1s
    Recognized Expert Contributor
    • Aug 2007
    • 671

    #2
    Two questions:
    Was this C code? And second, if so, I assume it was not compiled with all warnings turned on?

    Comment

    • TKM
      New Member
      • Dec 2007
      • 11

      #3
      Originally posted by oler1s
      Two 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

      • weaknessforcats
        Recognized Expert Expert
        • Mar 2007
        • 9214

        #4
        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

        • oler1s
          Recognized Expert Contributor
          • Aug 2007
          • 671

          #5
          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

          • weaknessforcats
            Recognized Expert Expert
            • Mar 2007
            • 9214

            #6
            I am always heartened by comments such as yours that abandoning C for a real language, like C++, was a good idea.

            Comment

            Working...