I know it starts with #
, and it follows the preprocessing directives format. But does the preprocessor really care about it? The #pragma pack
, #pragma once
, and all other directives I know, are all proceeded by compilers. A comment in this question even states that #pragma
directive survives the pre-processing stage.
So my questions are:
#pragma
is for compiler, why is it considered a preprocessing directive? Is it just because it starts with #
?#pragma
?Why is #pragma considered a preprocessor directive?
Because the C standard says so. It is specified in the chapter preprocessing directives, C17 6.10.6. Other than that, the standard is intentionally very vague with what #pragma
should do, since the whole purpose is to do something compiler-specific. Or in case the pragma isn't recognized - ignore it.
How a certain compiler handles the contents of a pragma internally isn't specified.
Some pragmas obviously need to be pre-processed, notably the kind that enables/disables certain compiler behavior like #pragma warning ...
etc. Lots of them must be evaluated during pre-processing or the compiler won't know how to compile the code.
Does preprocessor really do something with #pragma?
Yes, it evaluates it in translation phase 4: "Preprocessing directives are executed, macro invocations are expanded, and _Pragma unary operator expressions are executed."
Please note that having a pre-processor separated from the compiler is mostly a theoretical model. In reality the pre-processor and compiler are often rather tightly integrated with each other.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With