Thread: Are comments compiled into and exe file?

  1. #1
    Registered User
    Join Date
    Jun 2007
    Posts
    9

    Are comments compiled into and exe file?

    Do comments get compiled into the exe file? Doesn't make sense that they are if they do since an exe file doesn't need them anyway.

    So are they automatically removed when the c-source code is compiled?

  2. #2
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    >Do comments get compiled into the exe file
    No.

    >So are they automatically removed when the c-source code is compiled?
    Yes.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,656
    A whole bunch of other stuff gets removed as well.

    So when someone asks you "can I see the source given the .exe", you know what the answer is.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #4
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    They're not removed so much as just ignored and skipped when the compiler is going through the source.

  5. #5
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by Chris2222 View Post
    Do comments get compiled into the exe file? Doesn't make sense that they are if they do since an exe file doesn't need them anyway.

    So are they automatically removed when the c-source code is compiled?
    In theory the compiler might store the comments inside the debugging information, if present. But I don't know of any compiler that actually does that. So, it's possible, but not something I've heard of.

  6. #6
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by MacGyver View Post
    They're not removed so much as just ignored and skipped when the compiler is going through the source.
    Depends a bit on how you look at it, really. A classic C-compiler consists of four stages:
    * cpp - preprocessor, deals with all #include, #define, #if and so, and also normally removes ALL comments.
    * cc1 - generates assembler code from the now preprocessed C-code.
    * as - assembler to object
    * ld - linker/loader - puts all object files together, reads libraries etc.

    Whilst most compilers don't consist of different parts in this manner any longer, they still follow pretty much this principle - first go through and do all the #include, #define, #if and remove comments, then compile the code after this stage. However, there are references to the original source and where in the source the code actually came from, so that a source level debugger can show you the original source-code. But that is in the form of line number and source-filename. As far as I know, no compiler stores the actual source code within the debug information.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed