Archives
D Programming
DD.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++ - CPP bug with complex macros
Hello, with all DMC versions I tested, I got compiler error for an undefined identifier of mine return nmul( a, b ); ^ macro-bug.c(14) : Error: undefined identifier 'FIXNUM' --- errorlevel 1 Of course, it works with MSVC++, gcc, bcc, lcc, SunCC, wcc, icc... Here is a simple test: -------------------------------------------------------- #define FIXNUM long #define FIXPTR unsigned long #define _fix(x) (((FIXNUM)x<0) ? 0 : (FIXNUM)x) #define olmakefix( x ) (((FIXPTR)(x))<<4) #define nmul( x, y ) olmakefix(_fix(x) * _fix(y)) int main() { FIXNUM a = (FIXNUM)0x10; FIXNUM b = (FIXNUM)0x10; return nmul( a, b ); } Oct 23 2003
You can workaround for now by using typedef's for FIXNUM rather than macros. -Walter "Christian Jullien" <Christian_member pathlink.com> wrote in message news:bn89a2$4l5$1 digitaldaemon.com...Hello, with all DMC versions I tested, I got compiler error for an undefined identifier of mine return nmul( a, b ); ^ macro-bug.c(14) : Error: undefined identifier 'FIXNUM' --- errorlevel 1 Of course, it works with MSVC++, gcc, bcc, lcc, SunCC, wcc, icc... Here is a simple test: -------------------------------------------------------- #define FIXNUM long #define FIXPTR unsigned long #define _fix(x) (((FIXNUM)x<0) ? 0 : (FIXNUM)x) #define olmakefix( x ) (((FIXPTR)(x))<<4) #define nmul( x, y ) olmakefix(_fix(x) * _fix(y)) int main() { FIXNUM a = (FIXNUM)0x10; FIXNUM b = (FIXNUM)0x10; return nmul( a, b ); } Oct 23 2003
In article <bn9c51$1ol2$1 digitaldaemon.com>, Walter says... It was just a simple example to exihibit the bug. It also occurs for index on vectors inside macros. Replacing #define INDEX 0 by and enum also fix the bug. I prefer waiting for the fix and leave my code alone. It works as is on more than 70 different systems. See http://www.eligis.com speciallay the port section at http://www.eligis.com/ports.html Thanks anyway.You can workaround for now by using typedef's for FIXNUM rather than macros. -Walter "Christian Jullien" <Christian_member pathlink.com> wrote in message news:bn89a2$4l5$1 digitaldaemon.com...Hello, with all DMC versions I tested, I got compiler error for an undefined identifier of mine return nmul( a, b ); ^ macro-bug.c(14) : Error: undefined identifier 'FIXNUM' --- errorlevel 1 Of course, it works with MSVC++, gcc, bcc, lcc, SunCC, wcc, icc... Here is a simple test: -------------------------------------------------------- #define FIXNUM long #define FIXPTR unsigned long #define _fix(x) (((FIXNUM)x<0) ? 0 : (FIXNUM)x) #define olmakefix( x ) (((FIXPTR)(x))<<4) #define nmul( x, y ) olmakefix(_fix(x) * _fix(y)) int main() { FIXNUM a = (FIXNUM)0x10; FIXNUM b = (FIXNUM)0x10; return nmul( a, b ); } Oct 23 2003
Here is an even smaller example with just constant macro. The bug seems to occur when, inside a macro, you use the same other macro twice (low in my example). ----------------------------------------------------- #define LOWPART 0xFF #define low(x) (x&LOWPART) #define identity( x ) (x) #define sum( x, y ) identity( low(x) + low(y) ) int main() { int a = 0x10; return sum( a, a ); } ----------------------------------------------------- In article <bn9ct6$1pqs$1 digitaldaemon.com>, Christian Jullien says...In article <bn9c51$1ol2$1 digitaldaemon.com>, Walter says... It was just a simple example to exihibit the bug. It also occurs for index on vectors inside macros. Replacing #define INDEX 0 by and enum also fix the bug. I prefer waiting for the fix and leave my code alone. It works as is on more than 70 different systems. See http://www.eligis.com speciallay the port section at http://www.eligis.com/ports.html Thanks anyway.You can workaround for now by using typedef's for FIXNUM rather than macros. -Walter "Christian Jullien" <Christian_member pathlink.com> wrote in message news:bn89a2$4l5$1 digitaldaemon.com...Hello, with all DMC versions I tested, I got compiler error for an undefined identifier of mine return nmul( a, b ); ^ macro-bug.c(14) : Error: undefined identifier 'FIXNUM' --- errorlevel 1 Of course, it works with MSVC++, gcc, bcc, lcc, SunCC, wcc, icc... Here is a simple test: -------------------------------------------------------- #define FIXNUM long #define FIXPTR unsigned long #define _fix(x) (((FIXNUM)x<0) ? 0 : (FIXNUM)x) #define olmakefix( x ) (((FIXPTR)(x))<<4) #define nmul( x, y ) olmakefix(_fix(x) * _fix(y)) int main() { FIXNUM a = (FIXNUM)0x10; FIXNUM b = (FIXNUM)0x10; return nmul( a, b ); } Oct 23 2003
"Christian Jullien" <Christian_member pathlink.com> wrote in message news:bnacnn$3f2$1 digitaldaemon.com...Here is an even smaller example with just constant macro. The bug seems to occur when, inside a macro, you use the same other macro Oct 24 2003
More isolation for this bug (it works well with 'old' 1997 Symantec 7.2B4n): ---------------------------- #define SOMEVALUE 0xFF #define same( x ) (x) #define identity( x ) (x) #define buggy( x ) identity( same(x) + SOMEVALUE ) int main() { int a = 0x10; return buggy( a ); } ---------------------------- C:\>dmc -e dmbug.c return ((a ) + SOMEVALUE ) ^ dmbug.c(11) : Error: undefined identifier 'SOMEVALUE' --- errorlevel 1 It works if you inverse arguments: #define buggy( x ) identity( SOMEVALUE + same(x) ) Nov 01 2003
|