Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

A silly belief shattered (happily)

0 views
Skip to first unread message

Alf P. Steinbach

unread,
Jul 28, 2009, 3:31:09 AM7/28/09
to
For as long as I can remember I have, incorrectly, believed that

MACRO ( whatever )

would not be a valid macro invocation.

Of course the space before "(" wreaks havoc with a macro-with-args /definition/,
and that may be where I got the impression from.

Anyway, with the space allowed much is simplified...


Cheers,

- Alf (amazed at the macro trickery in Boost Preprocessor)

Vladimir Jovic

unread,
Jul 28, 2009, 3:55:53 AM7/28/09
to
Alf P. Steinbach wrote:
> For as long as I can remember I have, incorrectly, believed that
>
> MACRO ( whatever )
>
> would not be a valid macro invocation.
>
> Of course the space before "(" wreaks havoc with a macro-with-args
> /definition/, and that may be where I got the impression from.
>
> Anyway, with the space allowed much is simplified...

For example?

Alf P. Steinbach

unread,
Jul 28, 2009, 4:14:45 AM7/28/09
to
* Vladimir Jovic:

#define FIRST( a, b, c ) a

#define BLAHBLAH( tuple ) FIRST tuple

int main()
{
BLAHBLAH( (42, 41, 43) ); // 42
}


Cheers,

- Alf

Vladimir Jovic

unread,
Jul 28, 2009, 4:25:10 AM7/28/09
to

Ok, so this:
BLAHBLAH ( 42, 41, 43 ); // 42
is causing a compilation error, but this:
BLAHBLAH ( (42, 41, 43) ); // 42
is not.

Is that what you are saying?

Ian Collins

unread,
Jul 28, 2009, 4:30:56 AM7/28/09
to

The key is

FIRST (42, 41, 43)

works.

--
Ian Collins

Alf P. Steinbach

unread,
Jul 28, 2009, 4:35:01 AM7/28/09
to

No, I'm saying that because the space is allowed one can easily let macros
produce other macro invocations, where the name of the macro to be invoked is a
parameter (otherwise, token-pasting via ## doesn't produce a valid token).

I've not done much macro stuff (obviously!).

But now I need some facility to simplify some notation, and I'm amazed at what's
possible using just the primitive C and C++ preprocessor.


Cheers,

- Alf

Puppet_Sock

unread,
Jul 28, 2009, 9:47:53 PM7/28/09
to
On Jul 28, 4:35 am, "Alf P. Steinbach" <al...@start.no> wrote:
[snip]

> No, I'm saying that because the space is allowed one can easily let macros
> produce other macro invocations, where the name of the macro to be invoked is a
> parameter (otherwise, token-pasting via ## doesn't produce a valid token).

Um. If I was in a code review, and I found such
a thing, I'd flag it as a code fault even if it
did "work."

> I've not done much macro stuff (obviously!).

This is a *good* thing.

> But now I need some facility to simplify some notation, and I'm amazed at what's
> possible using just the primitive C and C++ preprocessor.

I think there are better ways to simplify notation
than using macros the way you describe.

Indeed, I'm not real sure I'd say that this scheme
is aptly described as "simplifying" notation.
Socks

Alf P. Steinbach

unread,
Jul 28, 2009, 10:24:56 PM7/28/09
to
* Puppet_Sock:

> On Jul 28, 4:35 am, "Alf P. Steinbach" <al...@start.no> wrote:
> [snip]
>> No, I'm saying that because the space is allowed one can easily let macros
>> produce other macro invocations, where the name of the macro to be invoked is a
>> parameter (otherwise, token-pasting via ## doesn't produce a valid token).
>
> Um. If I was in a code review, and I found such
> a thing, I'd flag it as a code fault even if it
> did "work."

You'd have to flag the Boost Preprocessor library as a "code fault", then. ;-)

So as a general statement it makes no sense, but it depends on the context.

For example, in a sweatshop-like workplace it can make sense to impose literal
rules, because the grunt workers are just robots, or would be if such existed.
In other contexts the programmer's job is to apply intelligence and aesthetics,
something that robots following mechanical code-production rules would find
difficult or impossible to do. The application of intelligence and aestethics
can't be judged by literal rules, or rather, should ideally not be so judged,
for doing that will in most cases lower quality instead of raising it (the few
cases where it might raise quality being those where the rules are
coincidentally "right" *and* the programmer had a lapse of judgment).


>> I've not done much macro stuff (obviously!).
>
> This is a *good* thing.

:-)

I think I agree.


>> But now I need some facility to simplify some notation, and I'm amazed at what's
>> possible using just the primitive C and C++ preprocessor.
>
> I think there are better ways to simplify notation
> than using macros the way you describe.
>
> Indeed, I'm not real sure I'd say that this scheme
> is aptly described as "simplifying" notation.

It's good that you write you're not "real sure", since you don't know anything
about "this scheme". :-)


Cheers & hth.,

- Alf

0 new messages