HPlogo HP C/HP-UX Reference Manual: Version A.05.55.02 > Chapter 7 Preprocessing Directives

Line Control (#line)

» 

Technical documentation

Complete book in PDF

 » Table of Contents

 » Index

You can cause the compiler to increment line numbers during compilation from a number specified in a line control directive. (The resulting line numbers appear in error message references, but do not alter the line numbers of the actual source code.)

Syntax

line-directive ::=
#line digit-sequence [filename]

Description

The #line preprocessing directive causes the compiler to treat lines following it in the program as if the name of the source file were filename and the current line number is digit-sequence. This is to control the file name and line number that is given in diagnostic messages, for example. This feature is used primarily for preprocessor programs that generate C code. It enables them to force the HP C compiler to produce diagnostic messages with respect to the source code that is input to the preprocessor rather than the C source code that is output and subsequently input to the compiler.

HP C defines two macros that you can use for error diagnostics. The first is __LINE__, an integer constant equal to the value of the current line number. The second is __FILE__, a quoted string literal equal to the name of the input source file. Note that you can change

__FILE__ and __LINE__ using #include or #line directives.

Example

#line digit-sequence [filename]: #line 5 "myfile"

© Hewlett-Packard Development Company, L.P.