Adria Arroyo
Adria Arroyo

Reputation: 17

Preprocessor directive to create keywords in C

I want to create this...

int main(void) {
  int i;

  for(i = 0; i < 10; i++){
    //Not an important Code
  }
  return 0;
}

in a fancier way, to create crazy ideas!
Is it possible to rewrite it like this?

#define A f
#define B or

int main(void) {
  int i;

  AB(i = 0; i < 10; i++){
    //Not an important Code
  }
  return 0;
}

I need to know if it's possible to create instrctions like a simple for composed by diferent #defines

Upvotes: 1

Views: 111

Answers (1)

alinsoar
alinsoar

Reputation: 15793

making

#define A f
#define B or
#define C(x, y) x##y
#define D(x,y) C(x,y)

then

D(A, B)(i = 0; i < 10; i++)

will be rewritten as

for (i = 0; i < 10; i++)

Upvotes: 4

Related Questions