www.digitalmars.com Home | Search | C & C++ | D | DMDScript | News Groups | index | prev | next
Archives

D Programming
D
D.gnu
digitalmars.D
digitalmars.D.bugs
digitalmars.D.dtl
digitalmars.D.dwt
digitalmars.D.announce
digitalmars.D.learn
digitalmars.D.debugger

C/C++ Programming
c++
c++.announce
c++.atl
c++.beta
c++.chat
c++.command-line
c++.dos
c++.dos.16-bits
c++.dos.32-bits
c++.idde
c++.mfc
c++.rtl
c++.stl
c++.stl.hp
c++.stl.port
c++.stl.sgi
c++.stlsoft
c++.windows
c++.windows.16-bits
c++.windows.32-bits
c++.wxwindows

digitalmars.empire
digitalmars.DMDScript

c++ - [Bug report] Macros fail to expand

Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit

Under certain circumstances macros don't expand correctly.

     #define FOO(arg) arg

     #define CALL(x, y) CALL2(x(y))
     #define CALL2(result) result

     CALL(FOO, 1)

This should expand to '1', but it expands to FOO(1).

The same for:

     #define FOO(arg) arg

     #define CALL_ALT(x, y) CALL_ALT_2(x y)
     #define CALL_ALT_2(x) x

     CALL_ALT(FOO, (1))

I've attached some test cases from the wave preprocessor test suite 
which test this kind of thing in more detail. Wave is a highly compliant 
preprocessor implementation which is available from:

The //E lines indicate the expected result of the previous line's macro 
call. Although, I think that very few preprocessors will get 
test13/14/15.cpp right, so they're pretty pathological cases. Maybe only 
wave and gcc's preprocessor will get them right.

Daniel
Aug 12 2004