Given:
===Program <===
$ cat macro_delay_exp ansion.c
#define args(a,b) a, b
#define myprintf(a, b, c) do { \
printf("%d %d %d\n", a, b, c );\
} while(0)
#define nodelay(a, b) myprintf(a, b)
#define delaymacro_expa nd(a, b) nodelay(a, ##b)
int main() {
delaymacro_expa nd(1, args(2, 3));
}
===Error <===
$ gcc macro_delay_exp ansion.c
macro_delay_exp ansion.c:8:1: pasting "," and "args" does not give a
valid preprocessing token
$ /usr/local/remote/packages/icc_remote/9.1.046patched/bin/icc
macro_delay_exp ansion.c && echo success
success
$ ./a.out
1 2 3
===Compiler Version <===
gcc (GCC) 3.4.5 20051201 (Red Hat 3.4.5-2)
icc (ICC) 9.1 20070510
Compilers on aix, hpux and solaris also accept the syntax. Just that
gcc
does not.
HP (-Aa for strict ansi compliance)
$ /usr/local/packages/compiler_remote/ansicA.06.14_aC C.A.06.14/opt/
ansic/bin/cc -Aa a.c && ./a.out
1 2 3
AIX
$ $ORACLE_HOME/bin/oraxlc a.c && ./a.out
1 2 3
Solaris
$ /usr/local/packages/studio_remote/11/SUNWspro/bin/cc a.c && ./a.out
"a.c", line 10: warning: implicit function declaration: printf
1 2 3
IMHO, gcc is right: neither args(2,3) nor nodelay should be
expanded before the token pasting happens.
Thanks,
Jeff 1 4226
On Thu, 16 Oct 2008 10:10:14 -0700, jeff wrote:
Given:
===Program <===
#define delaymacro_expa nd(a, b) nodelay(a, ##b)
[...]
delaymacro_expa nd(1, args(2, 3));
===Error <===
$ gcc macro_delay_exp ansion.c
macro_delay_exp ansion.c:8:1: pasting "," and "args" does not give a
valid preprocessing token
[...]
Compilers on aix, hpux and solaris also accept the syntax. Just that gcc
does not.
[...]
IMHO, gcc is right: neither args(2,3) nor nodelay should be
expanded before the token pasting happens.
If token pasting does not result in a valid token, the behaviour is
undefined by the C standard, meaning no diagnostic is required. From what
I can see, gcc is right, but the other compilers are equally right,
because they are free to do whatever they want with the code. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Cronus |
last post by:
Hi
the following code the g++ (g++ (GCC) 3.3.3 (Debian 20040422)) emits the
error message that pasting of :: and hello is no valid preprocessor token.
The g++ 2.95.3 accepts the code. I know that handling of the ##
preprocessing operator has changed.
How I have to change the macro definiton of A(P)?
NO changes at macro calling should be necessary!
|
by: Frodo Baggins |
last post by:
Hi All,
I have a piece of code (not written by me) that is failing on compile with
the error:
pasting "xdr_ndmp_connect_open_request" and "," does not
give a valid preprocessing token
The relevant line from the header is:
#define XDR_AND_SIZE(func) (bool_t(*)(XDR*, ...))xdr_##func##,sizeof(func)
|
by: Chris |
last post by:
Hi all
We have a strange problem with macros:
#define SQLST_MAP_IND_O(Tbl,Fld) i##Tbl##_O=i##Tbl##_##Fld;
SQLST_MAP_IND_I(RAGREEJ1,FORMFROMTMSTP);
=> gcc 3.3.4 gives the following error:
source.c:173:40: pasting "[" and "RAGREEJ1" does not give a valid
|
by: Wessi |
last post by:
Hi,
token pasting means, that normally whitespaces and comments are deleted
before and after the ## operator. I want the preprocessor to hold an
existing whitespace while replacing the argument of a macro. Example:
The following define and macro
#define ISR_CAT1(NAME) __interrupt void ##NAME(void)
|
by: Nelson Hsu |
last post by:
Is there anything like the token pasting operator (##) in C#?
I'm trying to port some unmanaged C++ code into C# and I'm not sure
how to mimic this behavior.
| |
by: Mark Odell |
last post by:
I'm running two different compilers against some hairy macros and one,
gcc, doesn't like my token pasting result so much. It says, " "." and
"foo" does not give a valid preprocessing token ". Some further reading
suggests that since .foo is not a valid preproc. token that I can't
really do what I want, portably. The macro looks like this:
#define DMA_CHECK_SR_BIT(reg, REG, ch) do \
{ ...
|
by: Henry Townsend |
last post by:
I hope this is on-topic in c.l.c - it's about the C preprocessor more
than the language per se, more generally about the K&R behavior, and
most specifically about the Sun cpp which is why I've cross posted there.
The test case below is taken from an Imake setup (yes, old, I know).
There's a Concat() macro which uses old-style /**/ for token pasting (we
are not allowed to assume ANSI so ## isn't allowed). I'm trying to paste
AND expand...
|
by: mark.bergman |
last post by:
I am porting some old code from Digital Unix to Linux using token
pasting, which is failing to compile (code simplified):
#define DEBUG(strg,v) printf("debugoutput: "##strg##".\n", v);
main()
{
int x = 5;
DEBUG("variable x is %d",x);
}
|
by: Rudhir |
last post by:
Hi Everyone,
How can I paste tokens with a white space between them?
Because,
#define Paste(a,b) (a ## b)
doesn't put a white space between the tokens.
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |