It's not necessarily better style/design. And if the job of one function requires another function, then you should call the other function within the first function. You shouldn't use main to do it. And I'm kind of curious how to do this as well, which is why I am upping this topic. Its been a while since I've programmed in C, but I would think you'd just include the one header in the other one. Since you need to compile each file into a .o, I'm not sure where that comes into play though. Guess you'd just always have to link them somehow.
BestJewSinceJC
Posting Maven
2,772 posts since Sep 2008
Reputation Points: 874
Solved Threads: 354
Just put all the function definitions in one header file and have all the other headers include it. That way every function knows about every other function.
That's the worst solution. Now you have a huge scrap heap of all possible interfaces. It's hard to maintain such a heap, you have drastically increased compilation time and full project recompilation overheads on every new prototype added.
Look at extremelly rational C library headers structure. Group all your global functions, typedefs and global macros by themes. Place related declarations in correspondent .h files. Include only needed .h files in .c modules. Never mix unrelated function definitions in a single .c file.
If the most of your functions use common (as usually system) headers, place correspondent includes in the single common .h file (common.h, for example). Try to use precompiled headers feature of your compiler. For example, in VC++ place all system header include directives in stdafx.h.
Now your include police looks like:
/* .c file brief description */
#include "common.h"
#include "theme1.h"
#include "utility.h"
/* theme1 function definitions */
ArkM
Postaholic
2,001 posts since Jul 2008
Reputation Points: 1,234
Solved Threads: 348
I didn't quite understand that. I get the idea of using a common header for system includes. But the rest I wasn't sure of. Am I right in thinking this: include all formal function declarations first, then all their definitions?
I don't understand what's "formal function declaration". Have you ever seeninformal function declarations?
ArkM
Postaholic
2,001 posts since Jul 2008
Reputation Points: 1,234
Solved Threads: 348
ArkM
Postaholic
2,001 posts since Jul 2008
Reputation Points: 1,234
Solved Threads: 348