O
ooze
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);
??
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);
??