Passing commas into macros

G

Grey Plastic

How do I pass text that contains a comma into a macro? For example, I
have

#define ATTRIBUTE(name,type) ...

and I want to do

ATTRIBUTE(transitions, map<int,int>);

However, the last comma is being interpretted as the macro argument
delimiter, and I get the error

macro "ATTRIBUTE" passed 3 arguments, but takes just 2

Help?
 
G

Gianni Mariani

Grey said:
How do I pass text that contains a comma into a macro? For example, I
have

#define ATTRIBUTE(name,type) ...

and I want to do

ATTRIBUTE(transitions, map<int,int>);

Try

ATTRIBUTE(transitions, (map<int,int>))

Or, worst case

typedef map<int,int> map_int_int;
ATTRIBUTE(transitions, map_int_int)
 
A

Andrey Tarasevich

Grey said:
How do I pass text that contains a comma into a macro? For example, I
have

#define ATTRIBUTE(name,type) ...

and I want to do

ATTRIBUTE(transitions, map<int,int>);

However, the last comma is being interpretted as the macro argument
delimiter, and I get the error

macro "ATTRIBUTE" passed 3 arguments, but takes just 2
...

Use typedef-name for the type

typedef map<int,int> TMapIntInt;
ATTRIBUTE(transitions, TMapIntInt);
 
D

Derk Gwen

(e-mail address removed) (Grey Plastic) wrote:
# How do I pass text that contains a comma into a macro? For example, I
# have
#
# #define ATTRIBUTE(name,type) ...
#
# and I want to do
#
# ATTRIBUTE(transitions, map<int,int>);
#
# However, the last comma is being interpretted as the macro argument
# delimiter, and I get the error

In C, many of these kinds of constructs can be parenthesised
and avoid irritating cpp. If in C++ (map<int,int>) is equivalent to
map<int,int>, then you can use ATTRIBUTE(transitions, (map<int,int>));
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top