zsaleeba / picoc

A very small C interpreter
1.45k stars 183 forks source link

Macro expansion is self-contained #22

Open joesavage opened 8 years ago

joesavage commented 8 years ago

The following snippet outputs '10' rather than the expected value of '1' due to the way macro expansion is handled incorrectly in the interpreter:

#include <stdio.h>

#define NUM_ONE   0
#define NUM_TWO   1
#define NUM_THREE NUM_ONE + NUM_TWO

int main(void) {
    printf("%d\n", 10 * NUM_THREE);
    return 0;
}