jason said:
I have a question regarding type definitions. I usually put them in
header files. But I recently came over several discussions on the www.
And now I'm not to sure anymore if they go in .c file or in the header
files ?
What would be the correct way ?
The distinction between .C files and .H files is, from the compiler's point
of view, arbitrary. You could, if you wanted, put all the code in the .H
files and the header information in the .C files and most compilers would
play along with you. From the point of view of being able to compile it, it
makes no difference. If you just want the code to compile, put typedefs
anywhere you want.
However, .H files are used to expose the "interface" of a software module so
that other software modules may interact with it. The interface may involve
available functions, global variables, etc. Many times it is necessary to
have a type defined in order to use the interface.
Typedefs should go in the .H file if other software modules need to use them
for necessity or convenience.
You are definitely doing something wrong if either of the following occur:
a)You are repeating the same typedef in more than one file.
b)The compiler doesn't have enough information to check function definitions
against invocations.