NO

Author Topic: is this possible with macros ?  (Read 2697 times)

whatsup

  • Guest
is this possible with macros ?
« on: January 12, 2011, 10:16:05 PM »
i need a macro that will surround its argument with quotes

Code: [Select]
#define MyMacro(x)  "x"

// example:
// in the source file i will write:
a = MyMacro(abc);

//and the compiler will translate this to:

a = "abc"

is this possible in some way ?
« Last Edit: January 12, 2011, 10:19:49 PM by whatsup »

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2107
Re: is this possible with macros ?
« Reply #1 on: January 12, 2011, 10:35:58 PM »
Code: [Select]
#include <stdio.h>

#define TEST(x) "\""#x"\""

int main(int argc, char **argv)
{
printf(TEST(Hello));
return 0;
}

May the source be with you

whatsup

  • Guest
Re: is this possible with macros ?
« Reply #2 on: January 13, 2011, 12:29:44 AM »
thank you very very much sir.
it works!

CommonTater

  • Guest
Re: is this possible with macros ?
« Reply #3 on: January 13, 2011, 03:58:23 AM »
Interesting... but wouldn't it be easier to just type in the " marks?