How do I get compiler listing?

This is a discussion on How do I get compiler listing? within the C Programming forums, part of the General Programming Boards category; I'm using gcc on linux, and I want to see the code that the preprocessor expands. How do I get ...

  1. #1
    Registered User
    Join Date
    May 2009
    Posts
    3

    How do I get compiler listing?

    I'm using gcc on linux, and I want to see the code that the preprocessor expands. How do I get gcc to give me a compiler listing? I'm trying to do this so I can see the constants <errno.h> expands to.
    ---scott

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,845
    gcc -E
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    May 2009
    Posts
    3

    Re: How do I get a compiler listing?

    gcc -E only shows me the result of the outermost include, for example, /usr/include/errno.h. It doesn't show me the expansion of the included includes, like /usr/include/linux/errno.h. Is there a way to tell it to show all the includes?
    ---scott

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,845
    Huh?
    -E shows you what happens after ALL the pre-processing has happened.

    The file should be the fully expanded code.
    Look for embedded #file and #line comments which allow the compiler to reconstruct the original point in the code (for error messages).
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  5. #5
    Registered User
    Join Date
    May 2009
    Posts
    3

    More detail

    Here's more detail. I have a simple main.c:

    Code:
    #define _GNU_SOURCE 1
    #include <errno.h>
    int main()
    {
        return 0;
    }
    According to the output I get from gcc, this expands into about five other errno.h files. But I only get about two lines of C code and none of the error constants I know are in some of the other files. A lot of stuff like this:

    # 1 "main.c"
    # 1 "<built-in>"
    # 1 "<command-line>"
    # 1 "main.c"
    # 1 "/usr/include/errno.h" 1 3 4
    # 29 "/usr/include/errno.h" 3 4
    # 1 "/usr/include/features.h" 1 3 4
    # 330 "/usr/include/features.h" 3 4
    # 1 "/usr/include/sys/cdefs.h" 1 3 4
    # 348 "/usr/include/sys/cdefs.h" 3 4
    # 1 "/usr/include/bits/wordsize.h" 1 3 4
    # 349 "/usr/include/sys/cdefs.h" 2 3 4
    # 331 "/usr/include/features.h" 2 3 4
    # 354 "/usr/include/features.h" 3 4
    # 1 "/usr/include/gnu/stubs.h" 1 3 4
    # 1 "/usr/include/bits/wordsize.h" 1 3 4
    # 5 "/usr/include/gnu/stubs.h" 2 3 4
    # 1 "/usr/include/gnu/stubs-32.h" 1 3 4
    # 8 "/usr/include/gnu/stubs.h" 2 3 4
    # 355 "/usr/include/features.h" 2 3 4
    # 30 "/usr/include/errno.h" 2 3 4
    # 1 "/usr/include/bits/errno.h" 1 3 4
    # 25 "/usr/include/bits/errno.h" 3 4
    # 1 "/usr/include/linux/errno.h" 1 3 4
    # 1 "/usr/include/asm/errno.h" 1 3 4
    # 1 "/usr/include/asm-generic/errno.h" 1 3 4
    # 1 "/usr/include/asm-generic/errno-base.h" 1 3 4
    # 5 "/usr/include/asm-generic/errno.h" 2 3 4
    # 1 "/usr/include/asm/errno.h" 2 3 4
    # 5 "/usr/include/linux/errno.h" 2 3 4
    # 26 "/usr/include/bits/errno.h" 2 3 4
    # 43 "/usr/include/bits/errno.h" 3 4
    extern int *__errno_location (void) __attribute__ ((__nothrow__)) __attribute__ ((__const__));
    # 37 "/usr/include/errno.h" 2 3 4
    # 55 "/usr/include/errno.h" 3 4
    extern char *program_invocation_name, *program_invocation_short_name;
    # 1 "/usr/include/asm/errno.h" 2 3 4
    # 5 "/usr/include/linux/errno.h" 2 3 4
    # 26 "/usr/include/bits/errno.h" 2 3 4
    # 43 "/usr/include/bits/errno.h" 3 4
    extern int *__errno_location (void) __attribute__ ((__nothrow__)) __attribute__ ((__const__));
    # 37 "/usr/include/errno.h" 2 3 4
    # 55 "/usr/include/errno.h" 3 4
    extern char *program_invocation_name, *program_invocation_short_name;
    # 69 "/usr/include/errno.h" 3 4
    typedef int error_t;
    # 4 "main.c" 2
    # 1 "/usr/include/bits/errno.h" 1 3 4
    # 43 "/usr/include/bits/errno.h" 3 4
    extern int *__errno_location (void) __attribute__ ((__nothrow__)) __attribute__ ((__const__));
    # 5 "main.c" 2
    # 1 "/usr/include/asm/errno.h" 1 3 4
    # 7 "main.c" 2
    int main()
    {
    return 0;
    }

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,845
    errno.h has things like
    #define EAGAIN 11

    Which means in your code, if you have
    if ( errno == EAGAIN )

    You're always going to see
    if ( errno == 11 )

    You can get gcc to dump all sorts of information
    Preprocessor Options - Using the GNU Compiler Collection (GCC)
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. added start menu crashes game
    By avgprogamerjoe in forum Game Programming
    Replies: 6
    Last Post: 08-29-2007, 02:30 PM
  2. Compiler Paths...
    By Cobra in forum C++ Programming
    Replies: 5
    Last Post: 09-26-2006, 05:04 AM
  3. C Compiler and stuff
    By pal1ndr0me in forum C Programming
    Replies: 10
    Last Post: 07-21-2006, 12:07 PM
  4. I can't get this new compiler to work.
    By Loduwijk in forum C++ Programming
    Replies: 7
    Last Post: 03-29-2006, 06:42 AM
  5. how to call a compiler?
    By castlelight in forum C Programming
    Replies: 3
    Last Post: 11-22-2005, 11:28 AM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21