# keyword in C

I am trying to understand some kind of code, and I came across a keyword that I had never seen before. I tried to do this, but found nothing about him.

char *valtext; #line 1 "Values.l" #define INITIAL 0 #line 2 "Values.l" int reserve(char *s); #line 388 "lex.val.c" 

I turned on the whole block, hoping that maybe someone could help me understand this piece of code. I cannot find files on my system with the name "Values.l", and this piece of code is in the file "lex.val.c".

Thanks in advance.

+4
source share
5 answers
Directive

A #line sets the compiler setting for the current file name and line number. This affects the characters __FILE__ and __LINE__ , the output is generated by failed assert() and diagnostic messages (errors and warnings). It is usually used by the preprocessor, so error messages and warnings may refer to the source code, and not to the output of the preprocessor (which is usually discarded by the time you see any messages).

It is also used by other tools that generate C source code, such as lex / flex and yacc / bison, so error messages may refer to the input file rather than the (temporary) C code.

Definitive reference C standard (pdf), section 6.10.4.

View line

 #line number 

sets the current line number. View line

 #line number "file-name" 

sets the line number and file name. You can also generate one of these two forms by expanding macros; eg:

 #define LINE 42 #define FILE "foo.c" #line LINE FILE 
+9
source

The #line directive #line intended for use by preprocessors, so the source line number of the source can be passed to the C compiler. This #line that error messages from the compiler relate correctly to line numbers that the user will understand.

For example, line 12 of your mycode.c can go through the preprocessor, and now line 183 is mycode.tmp.cc. If the C compiler detects an error on this line, you do not need to report that the error is on line 183 of mycode.tmp.cc. Therefore, the C compiler needs to be given the "source coordinates" of each line. The #line directive does this by telling the compiler the current line number and file name for use in error messages.

+4
source

This code went through the pre-processor and as such is marked by one stage of the compiler, intended for consumption by another stage of the same compiler. The functions that it uses are not intended for your use.

The files that it refers to may be temporary files created by the compiler as they run.

0
source

This is done so that the line number changes .

This is done to display the line numbers of the input Lex file, for example, in error messages and warnings. Since Lex generates C code, without #line directives compile errors and warnings will not make any difference.

0
source

All Articles