473,396 Members | 2,129 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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 1304
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Vincent | last post by:
Hi I have a problem with pear DB my code : for ($i=0;$i<100000;$i) { $sql = "select id from table where id=x";
5
by: Henri | last post by:
Hi, I´ve searching for an reuseable SQL-Statement for follwoing situation: Having e.g. a table tblAdress with some fields like persons full name (as Name), City, Birthdate, Street and so on. ...
2
by: JosR | last post by:
I have a memory problem when running a VB.Net application. The application uses a from frmMain from which another form can be opened: Private Sub OpenTheNewForm() dim frm as New frmSecondform...
11
by: Squid Seven | last post by:
I create a pointer to an item: CardSession *cardSession; Then, later, I use new to create an instance of the item and assign it to that pointer: cardSession = new CardSession(); In...
2
by: SKC | last post by:
Is there a way to find the following in UDB ? 1. How many times an index is used for a duration ? 2. Which SQL/application is using the index? if not, is there a different way to find it ?
8
by: Gaijinco | last post by:
I have always indirectly know how RAM is used when a C++ program is run, but I wanted to be sure I got it right: First the OS copies the whole program to RAM. Every statement of the kind int x;...
7
by: Leonel Gayard | last post by:
Hi all, I had to write a small script, and I did it in python instead of shell-script. My script takes some arguments from the command line, like this. import sys args = sys.argv if args ==...
2
by: mghale | last post by:
Hello, I have to create a trigger to accomplish the following: Before the insert into table A occurs, the trigger must check to see if the combination of two columns (from the insert...
3
by: Ehsan | last post by:
hi coulde any one show me the usage of "yield" keyword specially in this example: """Fibonacci sequences using generators This program is part of "Dive Into Python", a free Python book for...
36
by: mdh | last post by:
May I ask the group this somewhat non-focused question....having now seen "continue" used in some of the solutions I have worked on. ( Ex 7-4 solution by Tondo and Gimpel comes to mind) Is there a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.