

















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


















Dave Eckhardt Dave Eckhardt Todd Mowry Todd Mowry L08a_define
“Don't make me stop the car...”
What's wrong with this picture? What's wrong with this picture?
From: Dave Eckhardt Subject: keyboard buffer size Keyboard buffers must handle somebody placing a cat on the keyboard (the 101-key keyboard).
Photo credit: Ivan Jager, 2006-10-
int scanbuf[64]; int getchar(void) { ... if (++bufindex == 256) bufindex = 0; ... }
#define KSB_SIZE 256 int scanbuf[KSB_SIZE]; int getchar(void) { ... if (++bufindex == KSB_SIZE) bufindex = 0; ... }
How to fix How to fix halfhalf of the problemof the problem % grep 64 *.c Wrong Wrong twotwo waysways (^) Won't find 63 (^) Will find random unrelated 64's
#define CENTER_X 40 #define CENTER_Y 12 ... set_cursor_pos(CENTER_Y, CENTER_X); ...
p->regsave[-18] |= 0x402; ... Don't make me stop the car...... Don't make me stop the car......
#define INC_TWICE(x) ++x; ++x // Note: only one ';'
#define INC_TWICE(x) ++x; ++x INC_TWICE(ac); ⇒ ++ac; ++ac;
#define INC_TWICE(x) ++x; ++x INC_TWICE(ac); ⇒ ++ac; ++ac; if (ac) INC_TWICE(ac);
#define INC_TWICE(x) ++x; ++x What to do? What to do? (^) See “multi-line macro”
#define TWICE(x) 2x TWICE(3) / 2*3 ⇒ 6 */