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
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 ...
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
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.
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
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.
Here's more detail. I have a simple main.c:
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:Code:#define _GNU_SOURCE 1 #include <errno.h> int main() { return 0; }
# 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;
}
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.