473,414 Members | 1,757 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,414 software developers and data experts.

Comma inside macro

Hello.

I experience a problem when calling a macro with an expression containing a
comma.

$ cat bug.c
#define M(x, y) x,y
#define A(x) x
#define B(x) A(x)

B(M(a,b))

$ gcc -E bug.c
....
bug.c:5:9: error: macro "A" passed 2 arguments, but takes just 1

GCC (all versions) fails with that error
HP-UX cc fails with similar error
Visual C++ (all versions) accepts that code and produces the obvious result:
a,b

Which compiler is right ?
How can I make GCC act as Visual C++ ?

--
Vincent Rivičre
Jun 27 '08 #1
1 1507
Hello Vincent,

You need parentheses:
#define M(x, y) ((x), (y))
#define M(x, y) x,y
raof01
mailto:ra****@gmail.com
"Thoughts are but dreams till their effects be tried." -- William Shakespeare
Jun 27 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: D | last post by:
How do you put a comma in a string that's passed as a function argument. The compiler thinks it's the end of that argument and I've tried the /, and "," but they don't seem to work.
11
by: Shawn Odekirk | last post by:
Some code I have inherited contains a macro like the following: #define setState(state, newstate) \ (state >= newstate) ? \ (fprintf(stderr, "Illegal...
2
by: s.subbarayan | last post by:
Dear all, What does this following piece of code do? #define CONVERT_SELF_PTR(type,in,out) \ (((in) != NULL) ? ((out) = (type *)(in), RETURN_OK) : ERROR_PARAM) especially can someone let...
2
by: grid | last post by:
Hi, I need some clarifications on how the comma operator is used to return values from function like macros.I saw a typical implementation as : #define sigfillset(ptr) ( *(ptr) &= ~(sigset_t)0 ,...
20
by: Srinivas Mudireddy | last post by:
Hi, I am facing a problem with trying to conditionally compile inside a macro. I have a macro #define SET_VAL(x, y) ((x) = *(y)) But the problem is y can be NULL in which case I want to set...
5
by: krbyxtrm | last post by:
Hi is there a way to 'manage' function execution using macros? #define MY_CALL_MACRO(MacroName) { g_MacroStack.push_back(MacroName); <some code here...>} such that when i use the...
17
by: Frederick Gotham | last post by:
I know there's a sequence point at a comma, e.g.: int main(void) { int a = 1; a++, ++a, a *= 3, a <<= 4; /* Perfectly okay */ }
7
by: MattyWix | last post by:
Hi, How can I pass a semicolon or a comma as a macro argument. I wish to build an expression that in some cases has a comma - eg building a list of members for a structure, but in other...
6
by: pedroalves | last post by:
Hi all, This is not a question about how to #define COMMA , Please keep reading. Recently in binutils, we introduced a macro like this: #define STRING_COMMA_LEN(STR) \ (STR), ((STR) ?...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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...
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
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...

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.