This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: rfc: macros accepting constructors


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]