Why does the GCC Compiler not Support #pragma startup and #pragma exit directives?

Viewed 542

I am a rookie in C language and was trying to learn the #pragma preprocessor directive. I looked up on Google and found this link: GeeksforGeeks Pragma Directive in C

In this link, they said that the #pragma startup and the #pragma exit Directives don't work in the GCC compiler. Why is it so??

I wrote the same program as given using the MinGW GCC compiler and it said the following warning:

warning: ignoring #pragma startup func1 [-Wunknown-pragmas]|

warning: ignoring #pragma exit func2 [-Wunknown-pragmas]|

2 Answers

Per GCC's documentation on pragma,

The #pragma directive is the method specified by the C standard for providing additional information to the compiler, beyond what is conveyed in the language itself. . . . A C compiler is free to attach any meaning it likes to other pragmas."

Neither of the directives you mention are defined by the C standard, so there is no reason to expect that they would work on different compilers. As mentioned in the article you linked, GCC chooses to use a different vector-specific feature for communicating that a function should be called before or after main, namely function attributes.

From gcc website: https://gcc.gnu.org/onlinedocs/gcc/Pragmas.html#Pragmas

  1. GCC supports several types of pragmas, primarily in order to compile code originally written for other compilers . Note that in general we do not recommend the use of pragmas.

  2. There is some overlap between the purposes of attributes and pragmas (see Pragmas Accepted by GCC). It has been found convenient to use attribute to achieve a natural attachment of attributes to their corresponding declarations, whereas #pragma is of use for compatibility with other compilers or constructs that do not naturally form part of the grammar.

From gcc website, it is very clear that usage of #pragma is supported, but not recommeded.

Reference for 2 point :https://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html#Function-Attributes

Related