CS 220 Parallel Computing

compilation.c

DownloadView Raw

/**
 * compilation.c
 *
 * Illustrates how a C file is manipulated by various stages of the compilation
 * process.
 *
 * Preprocessing:
 *     gcc -E compilation.c > compilation.pre
 *     (view compilation.pre in your text editor)
 *
 * Translation:
 *     gcc -S compilation.c
 *     (creates compilation.s with assembly code -- viewable in your editor)
 *
 * Linking / creating object code:
 *     gcc -c compilation.c
 *     (view with: hexdump -C compilation.o)
 */

#include <stdio.h>

/* We define some values here. They will be taken by the preprocessor and
 * inserted into our code */
#define GREETING "Hello"
#define FAVORITE_NUMBER 42

/* This constant integer will not be inserted directly into the code by the
 * preprocessor. */
const int OTHER_NUMBER = 10;

int main(void) {
    /* Let's say hello! I wonder if the preprocessor keeps these comments... */
    printf("Hi " "Class");
    printf(GREETING " world! My favorite number is %d but %d is great too.\n",
            FAVORITE_NUMBER, OTHER_NUMBER);
    return 0;
}