News:

Download Pelles C here: http://www.smorgasbordet.com/pellesc/

Main Menu

macro expansion

Started by czerny, July 29, 2014, 02:58:46 PM

Previous topic - Next topic

czerny

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'?).

JohnF

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

frankie

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...
"It is better to be hated for what you are than to be loved for what you are not." - Andre Gide

czerny

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?