c++ - CPP bug with complex macros
- Christian Jullien <Christian_member pathlink.com> Oct 23 2003
- "Walter" <walter digitalmars.com> Oct 23 2003
- Christian Jullien <Christian_member pathlink.com> Oct 23 2003
- Christian Jullien <Christian_member pathlink.com> Oct 23 2003
- "Walter" <walter digitalmars.com> Oct 24 2003
- Christian Jullien <Christian_member pathlink.com> Nov 01 2003
- "Walter" <walter digitalmars.com> Nov 09 2003
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
(low in my example).
Thanks for isolating this down for me. I'll let you know when I fix it. -Walter
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








"Walter" <walter digitalmars.com>