Preprocessor

M

mail.dsp

Can any body help me to define a preprocessor with variable no. of
argument which expands as follows:

PRE(SUNDAY, MONDAY, TUESDAY)

expands to

struct SUNDAY; struct MONDAY; struct TUESDAY, struct WEDNESDAY;

Keep in mind that this preprocessor accept variable no. of argument.
I tried boost preprocessor but I couldn't.
 
A

Alf P. Steinbach

* (e-mail address removed):
Can any body help me to define a preprocessor with variable no. of
argument which expands as follows:

PRE(SUNDAY, MONDAY, TUESDAY)

expands to

struct SUNDAY; struct MONDAY; struct TUESDAY, struct WEDNESDAY;

Don't use all uppercase except for macro names (and idiomatic usage).

Do make sure that your code is syntactically correct.

The above isn't.

Keep in mind that this preprocessor accept variable no. of argument.
I tried boost preprocessor but I couldn't.

Don't, it's stupid except as a learning exercise.

But if you were to do it, when you have progressed some from the current point
on the learning curve, then you can easily do it, although not with the exact
notation you exemplify above, with the Boost macro magic.

But then you will probably not want to. :)


Cheers & hth.,

- Alf
 
P

Phlip

Can any body help me to define a preprocessor with variable no. of
argument which expands as follows:

PRE(SUNDAY, MONDAY, TUESDAY)

expands to

struct SUNDAY; struct MONDAY; struct TUESDAY, struct WEDNESDAY;

Keep in mind that this preprocessor accept variable no. of argument.
I tried boost preprocessor but I couldn't.

use this:

http://www.codeproject.com/KB/macros/metamacros.aspx

However, if you need a different struct for each of a series of items, then you
might need a better design. See if you can DRY the design up with delegation or
inheritance of some type. ("Don't Repeat Yourself")
 
C

cr88192

Can any body help me to define a preprocessor with variable no. of
argument which expands as follows:

PRE(SUNDAY, MONDAY, TUESDAY)

expands to

struct SUNDAY; struct MONDAY; struct TUESDAY, struct WEDNESDAY;

Keep in mind that this preprocessor accept variable no. of argument.
I tried boost preprocessor but I couldn't.

I would have thought, as many common C++ implementations (such as GCC) share
the (default) preprocessor with their C implementation (many of which have
gone on to implement much of the C99 featureset), then the C99 style
variable-argument macros should work (it will require looking into, as it is
not "obvious"...).

however, as others have noted, for most things there is probable not much
use for vararg macros.

(FWIW, I don't understand your example...).
 
Z

Zachary Turner

I would have thought, as many common C++ implementations (such as GCC) share
the (default) preprocessor with their C implementation (many of which have
gone on to implement much of the C99 featureset), then the C99 style
variable-argument macros should work (it will require looking into, as it is
not "obvious"...).

however, as others have noted, for most things there is probable not much
use for vararg macros.

(FWIW, I don't understand your example...).

varargs macros are suitable only for passing the variable arguments
into a function which accepts variable numbers of arguments. i.e.

#define VARARG_MACRO(arg1, arg2, ...)
__VARARGS__

VARARG_MACRO(1, 2, 3, 4, 5, 6, 7)

While inside the invocation of this macro, the reserved identifier
__VARARGS__ (or something like that, I don't remmeber exactly) will
expand to the string literal "3, 4, 5, 6, 7"

In the original post, he wanted to actually declare variable numbers
of structures, so text would have to be inserted in between the
arguments and the commas deleted, which I don't believe is possible
with vararg macros.
 

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

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top