Skip to content

Instantly share code, notes, and snippets.

@kkdai
Last active August 29, 2015 13:56
Show Gist options
  • Save kkdai/9014911 to your computer and use it in GitHub Desktop.
Save kkdai/9014911 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <stdio.h>
#define FOO_Def
#define FOO_Def2 5
inline int foo1(int x)
{
return x*5+8;
}
#define macro(x) x* 5 + 8
#define FUN1(a,b) \
a=a*b;\
b +=1;\
a++;
//If override macro, will not compiler error. but will replace marco case last disappear
#define FUN2(a,b) \
{ a=a*b;\
b +=1;\
a++; }
int main(int argc, const char * argv[])
{
printf("X=%d, X*5=%d]\n", macro(5+3), macro(6+1)*5);
// it become 5+3*5+8 6+1*5+8*5
printf("X=%d, X*5=%d]\n", foo1(5+3), foo1(6+1)*5);
// it become (5+3)*5+8 ((6+1)*5+8)*5
int x=1, y=1;
for (int i=0; i<=5; i++)
FUN1(x,y);
printf("X=%d, Y=%d\n", x, y);
//Be careful this case will become
//
// for (int i=0; i<=5; i++)
// { a=a*b; }
// b +=1;\
for (int i=0; i<=5; i++)
FUN1(x,y);
printf("X=%d, Y=%d\n", x, y);
#ifdef FOO_Def
printf ("FOOO\n");
#endif
#ifdef FOO_Def2
printf ("FOOO\n");
#endif
//if (0==FOO_Def) Compiler will error
if (0==FOO_Def2) //Need define value for value check.
printf ("FOOO\n");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment