Thread: The C Compiler

  1. #1
    null pointer Structure's Avatar
    Join Date
    May 2019
    Posts
    338

    Lightbulb The C Compiler



    Does gcc compile to assembly or machine code ?
    "without goto we would be wtf'd"

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    GCC 9.2 Manual section 3.2 Options Controlling the Kind of Output

    Note that "object file" and "executable file" imply "machine code" in this context, although not all object files or executable files necessarily involve machine code (e.g., a shell script could be considered an "executable file", but that's in a completely different context).
    Last edited by laserlight; 01-07-2020 at 07:30 AM.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Dec 2019
    Posts
    5
    Both
    First it runs the preprocessor to expand macros, compiles to assembler, compiles that to object code and links it into the final output.

    -Greg.

  4. #4
    null pointer Structure's Avatar
    Join Date
    May 2019
    Posts
    338
    compiles that to object code and links it into the final output.
    Linker (computing) - Wikipedia ?
    "without goto we would be wtf'd"

  5. #5
    null pointer Structure's Avatar
    Join Date
    May 2019
    Posts
    338
    but that's in a completely different context
    Is object compiling required as in you can't skip it in a compiler ?
    "without goto we would be wtf'd"

  6. #6
    Registered User
    Join Date
    Dec 2019
    Posts
    5
    Quote Originally Posted by Structure View Post
    Yes. Although, if you read from the link provided by laserlight you'll see you can emit that step and and only output an object file (-c).

  7. #7
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by Structure View Post
    Is object compiling required as in you can't skip it in a compiler ?
    Read the GCC manual entry that I linked. It explains what you want to know.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  8. #8
    Registered User
    Join Date
    Dec 2019
    Posts
    5
    gcc actually stands for gnu compiler collection and it while you are asking about C (since it's a C forum) it can compile other languages as well and be extended by a programmer to do other things. It actually produces an intermediary form called RTL which is used in optimization passes - something many compilers do. If you are interested you can read more here: GNU Compiler Collection (GCC) Internals: Top.

  9. #9
    null pointer Structure's Avatar
    Join Date
    May 2019
    Posts
    338
    Some compilers... compile C and C++ source code directly into machine code... GCC on the other hand compiles C and C++ into assembly language...
    x86 Disassembly/Assemblers and Compilers - Wikibooks, open books for an open world
    "without goto we would be wtf'd"

  10. #10
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    You would have found that more authoritatively just by reading the manual entry I linked:
    Compilation can involve up to four stages: preprocessing, compilation proper, assembly and linking, always in that order. GCC is capable of preprocessing and compiling several files either into several assembler input files, or into one assembler input file; then each assembler input file produces an object file, and linking combines all the object files (those newly compiled, and those specified as input) into an executable file.

    (...)

    If you only want some of the stages of compilation, you can use -x (or filename suffixes) to tell gcc where to start, and one of the options -c, -S, or -E to say where gcc is to stop.
    So it's clear that the output of "compilation proper" is in assembly language, but more loosely speaking the overall compilation process can involve any or all of the four stages listed, the last two of which result in machine code.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 5
    Last Post: 04-23-2012, 07:54 AM
  2. Replies: 7
    Last Post: 12-13-2010, 10:02 PM
  3. Replies: 4
    Last Post: 09-12-2009, 01:10 PM
  4. Replies: 2
    Last Post: 02-04-2008, 02:34 AM
  5. hp iPAQ 6300 && C compiler || C# compiler
    By xddxogm3 in forum Tech Board
    Replies: 2
    Last Post: 12-07-2004, 07:28 AM

Tags for this Thread