View Full Version : C Macro Inserting
Mr.Macdonald
October 13th, 2010, 08:19 PM
I want a macro
#define mac(x)
to do this
mac(add)
--Yields-->
__add__
GeneralZod
October 13th, 2010, 08:26 PM
Do you mean something like this?
#include <stdio.h>
#define mac(x) __ ## x ## __
int main(void)
{
int mac(x) = 3;
printf("__x__ = %d", __x__);
return 0;
}
Edit:
(See here (http://gcc.gnu.org/onlinedocs/gcc-3.2.3/cpp/Concatenation.html#Concatenation) if you are curious).
nvteighen
October 14th, 2010, 07:35 AM
Do you mean something like this?
#include <stdio.h>
#define mac(x) __ ## x ## __
int main(void)
{
int mac(x) = 3;
printf("__x__ = %d", __x__);
return 0;
}
Edit:
(See here (http://gcc.gnu.org/onlinedocs/gcc-3.2.3/cpp/Concatenation.html#Concatenation) if you are curious).
Interesting... and this is even a standard preprocessor feature!
worksofcraft
October 14th, 2010, 07:45 AM
Interesting... and this is even a standard preprocessor feature!
Yes... once again GeneralZod explains it so completely and so succinctly. He really does know C/C++ inside out I think!
GeneralZod
October 14th, 2010, 08:33 AM
Yes... once again GeneralZod explains it so completely and so succinctly. He really does know C/C++ inside out I think!
A long way away from this, alas :)
Oh, and I should probably point out: identifiers beginning with a double-underscore (like our __x__) are reserved for use by standard libraries and should generally be avoided, but I'm not sure if this applies only to C++ and not C.
Powered by vBulletin® Version 4.2.2 Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.