I am new to the C programming language and gcc.
I am trying to decipher a rather complex C program. I would like to read a helpful listing file instead of the source file.
I am looking for a listing file created by the gcc compiler that contains:
i++;
, then a note saying were i
is declared.I did a search for this, but gcc has so many options, I got lost.
If there is a better place to ask my question, please let me know.
Well, I AM old-school, and what the OP needs is pre-processor output, and yes it can be more edifying than an IDE. The preprocessor handles all of the # statements, like #include and #ifdef. So it shows you what eventually becomes the input to the compiler. The g++ man page explains the 4 steps: preprocessing, compilation, assembly and linking
and it goes on to explain that the sequence can be stopped at any point. Then under "Preprocessor Options", the way to control this is explained. As another post stated, -E will do the trick, but that is only part of the answer. For finer control use the -f family of options, such as -fdirectives-only. So probably what the OP wants is:
gcc -E -fdirectives-only -o MySrc.lst MySrc.cpp
For those using C++, I recommend using g++ directly:
g++ -E -fdirectives-only -o MySrc.lst MySrc.cpp
The desired listing is then in MySrc.lst
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With