"? I just came across a C file that contains both preprocessor directives and strings that...">

What does the preprocessor do with "# <number> <filename>"?

I just came across a C file that contains both preprocessor directives and strings that look like this:

 # 9 "filename" 

I have never seen such lines before. What do they mean? I assume these are preprocessor directives, but what does the preprocessor do with them?

Also, for some lines, the line does not even represent the existing file name ...

+6
source share
1 answer

I believe this is another way of using the # line preprocessor directive.

For example, you can write:

 // you could write #line 7 "filename" or // # 7 "filename" or // # 7 or #line 7 int main(void) { printf("%d\n", __LINE__); 

And all of them will give you (in this case) 10 on stdout .

And the note about the "filename" part is optional and unverified (why it could be anything, even a file that does not exist). Its use is explained in the link provided -
If you specify a file name, the compiler views the next line as part of the specified file. If you do not specify a file name, the compiler views the next line as part of the current source file.

+4
source

All Articles