This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: rfc: macros accepting constructors
- From: Bo Thorsen <bo at sonofthor dot dk>
- To: Andreas Schwab <schwab at suse dot de>,Daniel Berlin <dberlin at dberlin dot org>
- Cc: Tim Hollebeek <tim at hollebeek dot com>,Aldy Hernandez <aldyh at redhat dot com>,Joern Rennecke <joern dot rennecke at superh dot com>, <jason at redhat dot com>,<gcc at gcc dot gnu dot org>, <geoffk at redhat dot com>
- Date: Fri, 28 Jun 2002 09:51:19 +0200
- Subject: Re: rfc: macros accepting constructors
- References: <Pine.LNX.4.44.0206271315540.23942-100000@dberlin.org> <jeadpf2756.fsf@sykes.suse.de>
On Friday 28 June 2002 09:29, Andreas Schwab wrote:
> Daniel Berlin <dberlin@dberlin.org> writes:
> |> On Thu, 27 Jun 2002, Tim Hollebeek wrote:
> |> > On Thu, Jun 27, 2002 at 10:02:32AM -0700, Aldy Hernandez wrote:
> |> > > > Perhaps the best suggestion (if anything is desirable) is to
> |> > > > modify grammar so that ()'s are allowed around any grammar element
> |> > > > which is surrounded by {}'s. Then all you have to do is remember
> |> > > > to use ({ and
> |> > >
> |> > > this already works.
> |> >
> |> > I think you misunderstood. The part of the grammar I was proposing to
> |> > modify was the C grammar, not the preprocessor grammar. What I
> |> > suggested most definitely does NOT work right now:
> |> >
> |> > d1.c: void foo(void) ({ int x, y; })
> |> > d2.c: int x[2] = ({ 0, 0 });
> |> >
> |> > d1.c:1: parse error before `{'
> |> > d2.c:1: braced-group within expression allowed only inside a function
> |> >
> |> > > but foo({1,2}) doesn't.
> |> >
> |> > What I'm proposing would allow foo({1,2}) to safely be rewritten as
> |> > foo(({1,2})) regardless of how the { ends up getting used.
> |>
> |> This conflicts with statement expressions (a gcc extension), probably
> |> irreconciably.
> |>
> |> ({1,2}) is an almost valid statement expression with the value "2".
> |>
> |> (It's invalid because you don't have a semicolon at the end of the 2)
> |>
> |> Thus, foo(({1,2;})) would be equivalent to foo(2).
> |> Try it, you'll get a "too many arguments" error if you have "void
> |> foo(void)", rather than some other weird error.
>
> Going back to the OP's question, it was about this:
>
> #define foo(x) bar((x))
>
> foo((vector int){0, 1, 2, 3});
>
> Since you can put parens around *every* valid expression, what is wrong
> with writing this?
>
> foo(((vector int){0, 1, 2, 3}));
I'm probably wrong, but to me it sounded like the guys where smoking the old
"but macros should behave exactly like functions" pipe. Looks like the smoke
haven't cleared yet.
Bo.
--
Bo Thorsen | Praestevejen 4
Free software developer | 5290 Marslev
SuSE Labs | Denmark