1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | #include <stdio.h>
// LOG function to print an integer.
#define logd(x) printf("The value of %s is %d\n", #x, (x))
// When the preprocessor replaces this, `x` in the right-hand-side (RHS)
// will be replaces with the argument to logd(..).
//
// No parentheses or anything extra is assumed.
//
// `#x` will be replaces by the text of the argument to logd(..).
void foo() {
printf("in foo\n");
}
int main(int argc, char *argv[]) {
int a = 3;
logd(a + 2 * 3);
foo();
foo();
foo();
return 0;
}
/* OUTPUT
The value of a is 3
in foo
in foo
in foo
*/
|
© Copyright 2016 Alexander J. Quinn This content is protected and may not be shared, uploaded, or distributed.