RAD Studio
ContentsIndex
PreviousUpNext
Converting To Strings With #

The # symbol can be placed in front of a formal macro argument in order to convert the actual argument to a string after replacement. 

Given the following definition:

#define TRACE(flag) printf(#flag "=%d\n", flag)

the code fragment

int highval = 1024;
TRACE(highval);

becomes

int highval = 1024;
printf("highval" "=%d\n", highval);

which, in turn, is treated as

int highval = 1024;
printf("highval=%d\n", highval);
Copyright(C) 2008 CodeGear(TM). All Rights Reserved.
What do you think about this topic? Send feedback!