RAD Studio |  |

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:

Copy Code

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

the code fragment

Copy Code

    int highval = 1024;
    TRACE(highval);

becomes

Copy Code

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

which, in turn, is treated as

Copy Code

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

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!