5 diagnostics the directive error causes the

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

View Full Document Right Arrow Icon
5 Diagnostics The directive ‘ #error ’ causes the preprocessor to report a fatal error. The tokens forming the rest of the line following ‘ #error ’ are used as the error message. You would use ‘ #error ’ inside of a conditional that detects a combination of parameters which you know the program does not properly support. For example, if you know that the program will not run properly on a VAX, you might write #ifdef __vax__ #error "Won’t work on VAXen. See comments at get_last_object." #endif If you have several configuration parameters that must be set up by the installation in a consistent way, you can use conditionals to detect an inconsistency and report it with #error ’. For example, #if !defined(FOO) && defined(BAR) #error "BAR requires FOO." #endif
Image of page 47

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

View Full Document Right Arrow Icon
Chapter 6: Line Control 44 The directive ‘ #warning ’ is like ‘ #error ’, but causes the preprocessor to issue a warn- ing and continue preprocessing. The tokens following ‘ #warning ’ are used as the warning message. You might use ‘ #warning ’ in obsolete header files, with a message directing the user to the header file which should be used instead. Neither ‘ #error ’ nor ‘ #warning ’ macro-expands its argument. Internal whitespace se- quences are each replaced with a single space. The line must consist of complete tokens. It is wisest to make the argument of these directives be a single string constant; this avoids problems with apostrophes and the like. 6 Line Control The C preprocessor informs the C compiler of the location in your source code where each token came from. Presently, this is just the file name and line number. All the tokens resulting from macro expansion are reported as having appeared on the line of the source file where the outermost macro was used. We intend to be more accurate in the future. If you write a program which generates source code, such as the bison parser generator, you may want to adjust the preprocessor’s notion of the current file name and line number by hand. Parts of the output from bison are generated from scratch, other parts come from a standard parser file. The rest are copied verbatim from bison ’s input. You would like compiler error messages and symbolic debuggers to be able to refer to bison ’s input file. bison or any such program can arrange this by writing ‘ #line ’ directives into the output file. ‘ #line ’ is a directive that specifies the original line number and source file name for subsequent input in the current preprocessor input file. ‘ #line ’ has three variants: #line linenum linenum is a non-negative decimal integer constant. It specifies the line number which should be reported for the following line of input. Subsequent lines are counted from linenum . #line linenum filename linenum is the same as for the first form, and has the same effect. In addition, filename is a string constant. The following line and all subsequent lines are reported to come from the file it specifies, until something else happens to change that. filename
Image of page 48
Image of page 49
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