This is the mail archive of the 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]

preprocessor/3852: cpp: parantheses wrong in variable argument macros

>Number:         3852
>Category:       preprocessor
>Synopsis:       cpp: parantheses wrong in variable argument macros
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Fri Jul 27 19:16:01 PDT 2001
>Release:        gcc version 2.95.2 19991024 (release)
I was using the variable macro arguments feature of cpp and I noticed some problems with the parantheses.  I haven't tried it on gcc 3.0.

Here is the source to test.c:

// here's something that works
#define TEST_GOOD(foo, args...) (foo, ## args)

// here's a variation that doesn't
#define TEST_BAD(foo, args...) (0, (foo), ## args)

// this is simpler and needs an argument to work
#define TEST_WORSE(args...) (0, ## args)

void main() {
  TEST_GOOD(0); // works
  TEST_BAD(0); // doesn't work
  TEST_WORSE(0); // works
  TEST_WORSE(); // doesn't work

If I run cpp test.c, I get 
# 1 "test.c"



void main() {
  ( 0  ) ;  
  (0, ( 0  ) ;  
  (0,0 ) ;  
   ) ;  



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