0

I want know about the steps of execution of c program. I got this intermediate file which i can't understand what are these numbers in the screenshot represent and what exactly that line it do.

# 1 "C:/Program Files (x86)/mingw-w64/i686-8.1.0-posix-dwarf-rt_v6-rev0/mingw32/i686-w64-mingw32/include/stdio.h" 1 3
# 9 "C:/Program Files (x86)/mingw-w64/i686-8.1.0-posix-dwarf-rt_v6-rev0/mingw32/i686-w64-mingw32/include/stdio.h" 3

take a look at ss

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
  • 1
    Please post code as `formatted text`, not images. Also provide the commands you're using to generate this file – ForceBru Apr 08 '20 at 12:39
  • Please don't show images of text. [Edit] your question and copy-paste a party of the text you wonder about into the question, *as text*. – Some programmer dude Apr 08 '20 at 12:40
  • 6
    Those are line numbers to match up preprocessed C with the original source, I think. With nested includes it can get fairly complex, but compilers can use this to print better warning messages (like where the original definition was of a conflicting prototype or something.) – Peter Cordes Apr 08 '20 at 12:41
  • what is .i file? – 0___________ Apr 08 '20 at 12:55
  • for gcc .i file `#` means comment – 0___________ Apr 08 '20 at 12:57
  • @P__J__: `.i` is the default name for `gcc -E` preprocessed output. BTW, this is not actually assembly, it's preprocessed C. – Peter Cordes Apr 08 '20 at 12:59
  • @PeterCordes I know what gcc .i file is but OP did not mention it. So I aked the question – 0___________ Apr 08 '20 at 13:01
  • @rici: were you planning to leave a comment about where the answer to this question is buried somewhere on a question about a different topic ([What is the difference between #include and #include "filename"?](https://stackoverflow.com/q/21593))? I flipped through the answers and I don't see any talking about the `gcc -E` output metadata lines like `# 1 "filename" 1 3`. I don't see how this is duplicate of that; please explain or re-target to an actual duplicate. – Peter Cordes Apr 08 '20 at 13:32
  • 1
    @peter: sorry, I don't know how that happened. There are dozens of appropriate dupes: when i get to a machine with a usable intergace I'll add some mire. – rici Apr 08 '20 at 14:01
  • @rici: Ok, I'll leave it closed for now. My answer here doesn't go much beyond my comment anyway. – Peter Cordes Apr 08 '20 at 14:03

1 Answers1

1

.i files are where gcc -save-temps outputs preprocessed C. This is C, not assembly language. You'll find asm in the .s file.


Those are line numbers to match up preprocessed C with the original source. I don't know exactly what the number at the start vs. the one or two numbers after the filename mean. If you need to know the details, you might need to look at GCC internals, or maybe it's documented somewhere.

With nested includes it can get fairly complex, but compilers can use this to print better warning messages (like where the original definition was of a conflicting prototype or something).

GCC has the C preprocessor built-in to the compiler pass so I'm not sure it actually needs to (or can) read these "comment" metadata lines in the .i; in normal operation the main C->asm compiler pass knows file/line-number of everything it read without having to serialize it into this text format and back.

GCC does have options to read preprocessed-C as input, specifically -fpreprocessed which is on by default if you were to run gcc -c foo.i.

Indicate to the preprocessor that the input file has already been preprocessed. This suppresses things like macro expansion, trigraph conversion, escaped newline splicing, and processing of most directives. The preprocessor still recognizes and removes comments, so that you can pass a file preprocessed with -C to the compiler without problems. In this mode the integrated preprocessor is little more than a tokenizer for the front ends.

-fpreprocessed is implicit if the input file has one of the extensions .i, .ii or .mi. These are the extensions that GCC uses for preprocessed files created by -save-temps.

So this is what lets GCC still remove those lines starting with # that are like preprocessor directives. (Like #define or #include).

Community
  • 1
  • 1
Peter Cordes
  • 328,167
  • 45
  • 605
  • 847