Home > Enterprise >  Is the order of #include <...> items important in C?
Is the order of #include <...> items important in C?

Time:11-06

Are there difference in two below?

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>

and

#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>

Are there importance in code styling?

Are there any optimizations note about this order?

Are there any coding conventions?

(Know should consists functions in above headers!)

Conceptual. I have a question in deffinitions.

CodePudding user response:

Is there a difference? Yes. Is it important? No. #include basically copy-pastes the content of the header into your file. So the pre-processed form of your code does differ in your example, but as @tadman noted, headers should, and basically always are written in a way such that include order doesn't matter.

Are there importance in code styling?

You can use whichever order you like, often times formatters (like clang-format) will sort the includes.

Are there any optimizations note about this order?

No

  • Related