[c++] Macro charizing operator #@ w/o Microsoft's help?

Started by
3 comments, last by discman1028 15 years, 9 months ago
Basically, I want this:

#define TO_CHAR( a ) 'a'
...
TO_CHAR(x) ==> 'x' // btw, this gives us 'a'... :-(

(http://msdn.microsoft.com/en-us/library/91tt6dfs(VS.80).aspx) But in gcc. Let me know of any hacky way to do it, I can't think of one.
--== discman1028 ==--
Advertisement
Maybe this will help.
Wow a solution came from a colleague a couple secs later... :)

#define TO_CHAR(a) #a[0]
--== discman1028 ==--
That's pretty hacky. Not that the original task isn't hacky in itself :) Try

#define TO_CHAR(a) '##a##'

## is the token pasting operator.
Quote:Original post by Zahlman
#define TO_CHAR(a) '##a##'



That ain't compiling. (Trivia: MS does have an alternate syntax for literals of the form 'abcd', which makes a word out of three or four characters... one of my tries looked something like your suggestion, with only four chars though instead of five, and compiled, but was, of course, incorrect.)
--== discman1028 ==--

This topic is closed to new replies.

Advertisement