Thinking in C and *nix (CSC 282 2015S) : EBoards

CSC282 2015S, Class 08: Using Macros for Logging


Overview

Review

Macros are dangerous

    printf("%d\n", SQUARE(2+3));
    int x = 3;
    printf("%d\n", SQUARE(x++);
    printf("x= %d\n", x);

We should have defined it as

    #define SQUARE(X) ((X)*(X))

Interesting macro examples

Problems with Printf-Style Debugging

Solving with Macros

Using Macros for Generics