Preprocessor question

M

Mateusz_madi

Hi all, I have question about preprocessor. I fi have a program called
binary_s.c and i put it only on preprocessor like:
cc -E binary_s.c and i get strange output at the beginning of file
like:

# 1 "binary_s.c"
# 1 "<built-in>"
# 1 "<command-line>"
# 1 "binary_s.c"

What are those if I didn't included any libaries ?

Regards,
Mateusz
 
B

Ben Bacarisse

Mateusz_madi said:
Hi all, I have question about preprocessor. I fi have a program called
binary_s.c and i put it only on preprocessor like:
cc -E binary_s.c and i get strange output at the beginning of file
like:

# 1 "binary_s.c"
# 1 "<built-in>"
# 1 "<command-line>"
# 1 "binary_s.c"

What are those if I didn't included any libaries ?

These are internal to the implementation (gcc, from the look of it).
The implementation can make the result of running only the preprocessor
almost anything it likes since the C standard does not mandate anything
but the overall effect of translating a program. However, most
implementations try to make the output of the preprocessor valid C. The
standard permits almost anything after a # and most implementations take
advantage of this to do keep track of information they might need later
on in the translation process.

In this case, the lines record the position in the stream of tokens that
is being processed (mainly for error reporting). For example, if you
had -include x.h on the command line, any tokens resulting from it would
have appeared between the 3rd and 4th lines of you example (together
with a further '#' line to note the new file being processed). Any
errors in x.h can then be noted as coming from "x.h included from
command-line" or some such text.
 
G

Gene

Hi all, I have question about preprocessor. I fi have a program called
binary_s.c and i put it only on preprocessor like:
cc -E binary_s.c and i get strange output at the beginning of file
like:

# 1 "binary_s.c"
# 1 "<built-in>"
# 1 "<command-line>"
# 1 "binary_s.c"

The Preprocessor Output section of the Gnu CPP manual answers your
question in detail for gcc. There also this in case you want to get
rid of these lines:

Options:
-P
Inhibit generation of linemarkers in the output from the preprocessor.
This might be useful when running the preprocessor on something that
is not C code, and will be sent to a program which might be confused
by the linemarkers. See Preprocessor Output.
 
M

mt

These are internal to the implementation (gcc, from the look of it).
The implementation can make the result of running only the preprocessor
almost anything it likes since the C standard does not mandate anything
but the overall effect of translating a program.  However, most
implementations try to make the output of the preprocessor valid C.  The
standard permits almost anything after a # and most implementations take
advantage of this to do keep track of information they might need later
on in the translation process.

In this case, the lines record the position in the stream of tokens that
is being processed (mainly for error reporting).  For example, if you
had -include x.h on the command line, any tokens resulting from it would
have appeared between the 3rd and 4th lines of you example (together
with a further '#' line to note the new file being processed).  Any
errors in x.h can then be noted as coming from "x.h included from
command-line" or some such text.

test post
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top