Eric
Eric

Reputation: 35

structs, typedefs, and c header files; how to integrate without .c file

I have a project where I need a ton on structs, and as an example, I will use this codebyte (not from project)

  typedef struct THING{
        int a;
        int b;
        float stuff;
    } THING;

The question I have is can I have a header file containing these typedefs and structs (i.e. structures.h) WITHOUT a related code file (structures.c)? Or what would be the proper method to do this? Thanks

Upvotes: 1

Views: 68

Answers (1)

dbush
dbush

Reputation: 224072

There's no hard rule that a header file with a given name has to have a corresponding source file of the same name.

If your header only has struct type definitions and typedefs then there's no need for there to be a corresponding .c file. If the file had function or global variable declarations then they would need to be defined in a .c file somewhere, however that file doesn't have to have the same name as the .h file.

Upvotes: 3

Related Questions