3 obsolete features page 54 c99 introduces the pragma

Info icon This preview shows pages 49–51. Sign up to view the full content.

View Full Document Right Arrow Icon
Section 11.3 [Obsolete Features], page 54 . C99 introduces the _Pragma operator. This feature addresses a major problem with #pragma ’: being a directive, it cannot be produced as the result of macro expansion. _Pragma is an operator, much like sizeof or defined , and can be embedded in a macro. Its syntax is _Pragma ( string-literal ) , where string-literal can be either a normal or wide-character string literal. It is destringized, by replacing all ‘ \\ ’ with a single ‘ \ ’ and all \" ’ with a ‘ " ’. The result is then processed as if it had appeared as the right hand side of a ‘ #pragma ’ directive. For example, _Pragma ("GCC dependency \"parse.y\"") has the same effect as #pragma GCC dependency "parse.y" . The same effect could be achieved using macros, for example #define DO_PRAGMA(x) _Pragma (#x) DO_PRAGMA (GCC dependency "parse.y")
Image of page 49

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Chapter 7: Pragmas 46 The standard is unclear on where a _Pragma operator can appear. The preprocessor does not accept it within a preprocessing conditional directive like ‘ #if ’. To be safe, you are probably best keeping it out of directives other than ‘ #define ’, and putting it on a line of its own. This manual documents the pragmas which are meaningful to the preprocessor itself. Other pragmas are meaningful to the C or C ++ compilers. They are documented in the GCC manual. GCC plugins may provide their own pragmas. #pragma GCC dependency #pragma GCC dependency allows you to check the relative dates of the current file and another file. If the other file is more recent than the current file, a warning is issued. This is useful if the current file is derived from the other file, and should be regenerated. The other file is searched for using the normal include search path. Optional trailing text can be used to give more information in the warning message. #pragma GCC dependency "parse.y" #pragma GCC dependency "/usr/include/time.h" rerun fixincludes #pragma GCC poison Sometimes, there is an identifier that you want to remove completely from your program, and make sure that it never creeps back in. To enforce this, you can poison the identifier with this pragma. #pragma GCC poison is followed by a list of identifiers to poison. If any of those identifiers appears anywhere in the source after the directive, it is a hard error. For example, #pragma GCC poison printf sprintf fprintf sprintf(some_string, "hello"); will produce an error. If a poisoned identifier appears as part of the expansion of a macro which was defined before the identifier was poisoned, it will not cause an error. This lets you poison an identifier without worrying about system headers defining macros that use it. For example, #define strrchr rindex #pragma GCC poison rindex strrchr(some_string, ’h’); will not produce an error. #pragma GCC system_header This pragma takes no arguments. It causes the rest of the code in the current file to be treated as if it came from a system header. See Section 2.8 [System Headers], page 13 .
Image of page 50
Image of page 51
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern