TOC | Prev | Next

Macros for magic values

Macros get handled by the preprocessor to diminish cut'n'paste.

#define MAX_USERS 100
int *scores = malloc( MAX_USERS * sizeof(int) );
for ( int i = 0; i <= MAX_USERS; i++ ) {
    /* loop */
}

gets preprocessed into:

int *scores = malloc( 100 * sizeof(int) );
for ( int i = 0; i <= 100; i++ ) {
    /* loop */
}

Change the one instance of MAX_USERS, it changes throughout.

TOC | Prev | Next