Categories:
.NET (357)
C (330)
C++ (183)
CSS (84)
DBA (2)
General (7)
HTML (4)
Java (574)
JavaScript (106)
JSP (66)
Oracle (114)
Perl (46)
Perl (1)
PHP (1)
PL/SQL (1)
RSS (51)
Software QA (13)
SQL Server (1)
Windows (1)
XHTML (173)
Other Resources:
I am trying to use the ANSI stringizing preprocessing operator ....
I'm trying to use the ANSI ``stringizing'' preprocessing operator `#' to insert the value of a symbolic constant into a message, but it keeps stringizing the macro's name rather than its value.
✍: Guest
It turns out that the definition of # says that it's supposed to stringize a macro argument immediately, without further expanding it (if the argument happens to be the name of another macro). You can use something like the following two-step procedure to force a macro to be expanded as well as stringized:
#define Str(x) #x
#define Xstr(x) Str(x)
#define OP plus
char *opname = Xstr(OP);
This code sets opname to "plus" rather than "OP". (It works because the Xstr() macro expands its argument, and then Str() stringizes it.)
An equivalent circumlocution is necessary with the token-pasting operator ## when the values (rather than the names) of two macros are to be concatenated.
Note that both # and ## operate only during preprocessor macro expansion. You cannot use them in normal source code, but only in macro definitions.
2016-01-22, 1161👍, 0💬
Popular Posts:
How To Run a JUnit Test Class? A JUnit test class usually contains a number of test methods. You can...
What is the difference between "calloc(...)" and "malloc(...)"? 1. calloc(...) allocates a block of ...
How to convert a Unix timestamp to a Win32 FILETIME or SYSTEMTIME? The following function converts a...
How To Select Some Rows from a Table? - MySQL FAQs - SQL SELECT Query Statements with GROUP BY If yo...
How To Build WHERE Criteria with Web Form Search Fields? - MySQL FAQs - Managing Tables and Running ...