469,313 Members | 2,623 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,313 developers. It's quick & easy.

usage of # in the following statement

I have read the Programing language C

6.10.3.2 The # operator
Constraints
1 Each # preprocessing token in the replacement list for a
function-like macro shall be
followed by a parameter as the next preprocessing token in the
replacement list.
Semantics
2 If, in the replacement list, a parameter is immediately preceded by
a # preprocessing
token, both are replaced by a single character string literal
preprocessing token that
contains the spelling of the preprocessing token sequence for the
corresponding
argument. Each occurrence of white space between the argument's
preprocessing tokens
becomes a single space character in the character string literal.
White space before the
first preprocessing token and after the last preprocessing token
composing the argument
is deleted. Otherwise, the original spelling of each preprocessing
token in the argument
is retained in the character string literal, except for special
handling for producing the
spelling of string literals and character constants: a \ character is
inserted before each "
and \ character of a character constant or string literal (including
the delimiting "
characters), except that it is unspecified whether a \ character is
inserted before the \
character beginning a universal character name. If the replacement
that results is not a
valid character string literal, the behavior is undefined. The
character string literal
corresponding to an empty argument is "". The order of evaluation of #
and ## operators
is unspecified.
but I still could not figure out the usage of # in the FAQ. could
anyone help me? thanks in advance

in the FAQ , there is an example i can understand either
#define Str(x) #x
#define Xstr(x) Str(x)
#define OP plus
char *opname = Xstr(OP);
to produce the result opname="plus"

why can not i do it like the below:
#define str(x) #x
#define op plus
char * opname=str(op);
??
Nov 14 '05 #1
3 1194
On 28 Jun 2004 18:20:30 -0700, fj***@163.net (ooze) wrote:
I have read the Programing language C

6.10.3.2 The # operator
[definition snipped]
why can not i do it like the below:
#define str(x) #x
#define op plus
char * opname=str(op);
??


Because of this passage in 6.10.3.1:

After the arguments for the invocation of a function-like macro have
been identified, argument substitution takes place. A parameter in the
replacement list, unless preceded by a # or ## preprocessing token or
followed by a ## preprocessing token (see below), is replaced by the
corresponding argument after all macros contained therein have been
expanded.

--
Eric Amick
Columbia, MD
Nov 14 '05 #2
Eric Amick <er********@comcast.net> wrote in message news:<qo********************************@4ax.com>. ..
On 28 Jun 2004 18:20:30 -0700, fj***@163.net (ooze) wrote:
I have read the Programing language C

6.10.3.2 The # operator


[definition snipped]
why can not i do it like the below:
#define str(x) #x
#define op plus
char * opname=str(op);
??


Because of this passage in 6.10.3.1:

After the arguments for the invocation of a function-like macro have
been identified, argument substitution takes place. A parameter in the
replacement list, unless preceded by a # or ## preprocessing token or
followed by a ## preprocessing token (see below), is replaced by the
corresponding argument after all macros contained therein have been
expanded.


thanks, I see where I just lost
Nov 14 '05 #3
Eric Amick <er********@comcast.net> wrote in message news:<qo********************************@4ax.com>. ..
On 28 Jun 2004 18:20:30 -0700, fj***@163.net (ooze) wrote:
I have read the Programing language C

6.10.3.2 The # operator


[definition snipped]
why can not i do it like the below:
#define str(x) #x
#define op plus
char * opname=str(op);
??


Because of this passage in 6.10.3.1:

After the arguments for the invocation of a function-like macro have
been identified, argument substitution takes place. A parameter in the
replacement list, unless preceded by a # or ## preprocessing token or
followed by a ## preprocessing token (see below), is replaced by the
corresponding argument after all macros contained therein have been
expanded.

thanks, I see where I lost
Nov 14 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Vincent | last post: by
2 posts views Thread by JosR | last post: by
11 posts views Thread by Squid Seven | last post: by
2 posts views Thread by SKC | last post: by
8 posts views Thread by Gaijinco | last post: by
7 posts views Thread by Leonel Gayard | last post: by
2 posts views Thread by mghale | last post: by
3 posts views Thread by Ehsan | last post: by
36 posts views Thread by mdh | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Geralt96 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.