Given:
===Program <===
$ cat macro_delay_expansion.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_expand(a, b) nodelay(a, ##b)
int main() {
delaymacro_expand(1, args(2, 3));
}
===Error <===
$ gcc macro_delay_expansion.c
macro_delay_expansion.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_expansion.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_aCC.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 4203
On Thu, 16 Oct 2008 10:10:14 -0700, jeff wrote:
Given:
===Program <===
#define delaymacro_expand(a, b) nodelay(a, ##b)
[...]
delaymacro_expand(1, args(2, 3));
===Error <===
$ gcc macro_delay_expansion.c
macro_delay_expansion.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...
|
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...
|
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:...
|
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...
|
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...
|
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...
|
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()...
|
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: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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,...
|
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...
| |