Pelles C forum

Pelles C => Bug reports => Topic started by: czerny on July 29, 2014, 02:58:46 PM

Title: macro expansion
Post by: czerny on July 29, 2014, 02:58:46 PM
Maybe this is a bug!?

I discovered it while compiling the pixman library.


#define macro(a) bla_##a##_

void bla_1_2_(void) {;}

macro(1_2);


E:\c\main.c(70): error #2048: Undeclared identifier 'bla_1' (did you mean 'bla_1_2_'?).
E:\c\main.c(70): error #2001: Syntax error: expected ';' but found '_2_'.
E:\c\main.c(70): error #2048: Undeclared identifier '_2_' (did you mean 'z'?).
Title: Re: macro expansion
Post by: JohnF on July 29, 2014, 05:36:22 PM
Probably.

PellesC will compile the following


#define macro(a) bla_##a##_

void bla_12_(void){;}

int _cdecl main( void )
{
macro(12)();
return 0;
}


But not with void bla_1_2_(void){;}

VC6 compiles both.

John
Title: Re: macro expansion
Post by: frankie on July 29, 2014, 06:45:38 PM
For some mistery reason the parameter '1_2' is recognized a preprocessor number even if it is an invalid numeric constant (see compiler warnings).
To solve the problem the only solution I can find is to avoid that macro parameter could look as a number:

#define macro(a) bla##a##_        //Remove the underscore following 'bla'

void bla_1_2_(void) {;}

macro(_1_2);                     //Prepend the underscore here to make the parameter not a number...
Title: Re: macro expansion
Post by: czerny on July 30, 2014, 10:30:31 AM
As I wrote, this is done on many places in the pixman library and it would be a lot of work to change this on all occurences.

Could a moderator move this in the bug report section, please?