2

I would like to know how can I include a directory containig several headers in a C program instead of including all the headers one by one.

1
  • 5
    You can't, and there's a reason for that. Including lots of headers makes compilation slow and introduces unnecessary coupling in your program. Commented Jan 23, 2013 at 19:17

3 Answers 3

2

This is not directly possible in C. You must include headers individually or make some sort of preprocessing step in your makefile which synthesizes a header which #includes the others.

Sign up to request clarification or add additional context in comments.

Comments

2

There's no such facility in C. Create a master header file that includes everything that's in that directory, and have your clients include that.

A side-note: it's always better to know what exactly you are #include-ing, i.e. hand-pick needed header files, instead of doing this thing wholesale to avoid name clashes, unexpected macro expansion, circular dependencies, and what not.

Comments

2

You can write an header that individually includes the other headers and then include this header elsewhere. But an include directive can only include one single header.

Comments