Skip to content

Instantly share code, notes, and snippets.

@mrluanma
Created June 7, 2010 02:18
Show Gist options
  • Save mrluanma/428137 to your computer and use it in GitHub Desktop.
Save mrluanma/428137 to your computer and use it in GitHub Desktop.
/*
Description:
The "beauty" of C macro.
*/
#include <stdio.h>
#define PRODUCT(x) (x * x)
int main(int argc, char**argv)
{
int i = 3, j, k;
/*
j is 9.
*/
j = PRODUCT(i++);
/*
k is 49.
*/
k = PRODUCT(++i);
printf("%d %d\n", j, k);
return 0;
}
/*
$ cpp product.c | tail -18
int main(int argc, char**argv)
{
int i = 3, j, k;
j = (i++ * i++);
k = (++i * ++i);
printf("%d %d\n", j, k);
return 0;
}
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment