4 ms·
If I have data types defined as function arguments in header files, I need to include the headers for those data types. You do not need the definition of a str
by jws 16y ago
If I have data types defined as function arguments in header files, I need to include the headers for those data types.
You do not need the definition of a structure to use a pointer to it in a function prototype…
struct puzzle *newPuzzle( int difficulty, struct preferences *prefs);
…will compile just fine without the definition of struct puzzle. this let's you hide your opaque types inside the .c files or a private .h file.
- drblast 16y agoThere are other data types besides pointers to structs. Specifically, stdint.h data types are a good example (on linux). int myfunction(uint64_t arg0); When writing cross-platform code, there are typically a lot of these kinds of things going on. Also, I typically include data type definitions in header files if they're used in more than one context. If I define a new data type in a header file that depends on other data types, I have to include those headers in the header file. Let's say I'm writing an encoder/decoder for a protocol and I want to separate the encode functions from the decode functions. Maybe they're in separate programs. They'll both use the same data structures for the most part. It it's a network protocol the layers of dependencies can get pretty deep. This isn't a problem with a one-liner solution, it's "how do you structure a huge project to reduce weird dependency issues when compiling while keeping the code readable?"