This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: rfc: macros accepting constructors
- From: kaih at khms dot westfalen dot de (Kai Henningsen)
- To: gcc at gcc dot gnu dot org
- Date: 27 Jun 2002 09:27:00 +0200
- Subject: Re: rfc: macros accepting constructors
- Comment: Unsolicited commercial mail will incur an US$100 handling fee per received mail.
- Organization: Organisation? Me?! Are you kidding?
- References: <20020626074154.GA810@redhat.com>
aldyh@redhat.com (Aldy Hernandez) wrote on 26.06.02 in <20020626074154.GA810@redhat.com>:
> iso C stipulates that macros accepting arguments are grouped only by
> parentheses. so the code below, will fail because we think foo()
> is receiving 4 arguments instead of 1.
>
> #define foo(x) bar((x))
>
> foo((vector int){0, 1, 2, 3});
>
> main a.c:7:31: macro "foo" passed 4 arguments, but takes just 1
>
> the interesting thing is that this does not only affect vectors, but
> arrays, structures, and other aggregate types. since ANSI C allows
> for library functions to be macros, any such macros will fail if we
> pass aggregates as above.
It also hits Objective-C method calls (in square brackets) if they take
variadic parameters (and thus use commas):
foo([NSString stringWithFormat: @"bla=%s", bla]);
> the cleanest solution i can think of is modifying the preprocessor to
> allow grouping with curlies as well. can anyone think of a better
> solution?
The problem, of course, is that this breaks code who actually uses
prameters with unbalanced curlies or brackets. I'm pretty certain such
code exists.
MfG Kai