Search code examples
cincludeclanginclude-path

How to do all includes in source file?


Is it possible to write all includes in the source file?

Let's say we have to write a module called sum (sum.h/sum.c) that provides sum functions for all numeric types.

All function declarations are done in sum.h file as follows:

uint16_t sum(uint16_t a, uint16_t b); // uint16 sum function

in this case I have to include <stdint.h> in sum.h.

Is it possible, for any version of the C standard, to do this include in the source file sum.c?


Solution

  • Is it possible, for any version of the c standard, to do this include in the source file sum.c .

    It is possible in all versions of the C standard to include the standard header in the source file. In fact, doing so is arguably recommended.

    However, if you were asking if you could avoid including the header in sum.h while still relying on the typedef (and without forcing the code including sum.h to include the standard header before including sum.h: bad design!), no there's no C standard version where that's possible.