public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* the problem of "#define hash_hash # ## #"
@ 2009-01-24  6:58 f z
  2009-01-27  0:40 ` Matthew Woehlke
  0 siblings, 1 reply; 2+ messages in thread
From: f z @ 2009-01-24  6:58 UTC (permalink / raw)
  To: gcc-help

Hi , 

Anybody could help to explain the following code which is the example in C99 std!

/***********************************************************/
4 EXAMPLE In the following fragment:
#define hash_hash # ## #
#define mkstr(a) # a
#define in_between(a) mkstr(a)
#define join(c, d) in_between(c hash_hash d)
char p[] = join(x, y); // equivalent to
// char p[] = "x ## y";
The expansion produces, at various stages:
join(x, y)
in_between(x hash_hash y)
in_between(x ## y)
mkstr(x ## y)
"x ## y"
In other words, expanding hash_hash produces a new token, consisting of two adjacent sharp signs, but
this new token is not the ## operator.
/**********************************************************/

Where define this syntax "#define hash_hash # ## #" in std?

In C99 std, we all know that "'##' cannot appear at either end of a macro expansion". 

In this definiation of macro , the "hash_hash" are defined with "# ## #",but I don't know what is the mean of the first and last sharp(#).



      ___________________________________________________________ 
  好玩贺卡等你发,邮箱贺卡全新上线! 
http://card.mail.cn.yahoo.com/

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: the problem of "#define hash_hash # ## #"
  2009-01-24  6:58 the problem of "#define hash_hash # ## #" f z
@ 2009-01-27  0:40 ` Matthew Woehlke
  0 siblings, 0 replies; 2+ messages in thread
From: Matthew Woehlke @ 2009-01-27  0:40 UTC (permalink / raw)
  To: gcc-help

f z wrote:
> Hi , 
> 
> Anybody could help to explain the following code which is the example in C99 std!
> 
> /***********************************************************/
> 4 EXAMPLE In the following fragment:
> #define hash_hash # ## #
> #define mkstr(a) # a
> #define in_between(a) mkstr(a)
> #define join(c, d) in_between(c hash_hash d)
> char p[] = join(x, y); // equivalent to
> // char p[] = "x ## y";
> The expansion produces, at various stages:
> join(x, y)
> in_between(x hash_hash y)
> in_between(x ## y)
> mkstr(x ## y)
> "x ## y"
> In other words, expanding hash_hash produces a new token, consisting of two adjacent sharp signs, but
> this new token is not the ## operator.
> /**********************************************************/
> 
> Where define this syntax "#define hash_hash # ## #" in std?
> In this definiation of macro , the "hash_hash" are defined with "# ##
> #",but I don't know what is the mean of the first and last sharp(#).

Re-read your preprocessor specification. This is the symbol '#' 
concatenated ('##' preprocessor operator) with the symbol '#'. Which 
results in the string '##' being output.

This is apparently being used to get '##' into a literal string via a macro.

-- 
Matthew
Please do not quote my e-mail address unobfuscated in message bodies.
-- 
find / -user your -name base -print0 | xargs -0 chown us:cats -- Unknown

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2009-01-27  0:40 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-01-24  6:58 the problem of "#define hash_hash # ## #" f z
2009-01-27  0:40 ` Matthew Woehlke

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).