Your compiler's secret life

|
You know compilers go through stages right? Generaly one of those stages is to convert the programming language to the assembly language for that architecture. Then the assembler turns that into machine language that can be given to the processor. Here's how to use gcc such that it doesn't do the assembly step and prints the assembly to the stdout for you to examine or pipe

gcc -S -o - a.c Read on for a little dissection and/or go play with it and read the man page for gcc.

Here is a.c #include int main( int argc, char **argv ){ int i; printf("argc: %d\n",argc); for( i=0; i Let's look at that command again gcc -S -o - a.c

  • gcc is the gnu c compiler
  • -S means to stop at before the assembler stage
  • -o specifies the output. It says the next argument will be the filename to output to. Normall the compiler would send the output of the compiler to a.s. But we give the '-' character to it to indicate that it is to dump the output to STDOUT. This let's us catch it to 'less' with '| less' or a file with '> file'.
  • a.c is the file that we are compiling. It show a simple usage of argc and argv.

This is a great tool as a starting place for learning some of the differences is the assemblies between different architectures. You could take the same "Hello world" program and compile it using gcc on a number of readily accessible architectures (x86, ppc).