NO

Author Topic: macro expansion  (Read 2922 times)

czerny

  • Guest
macro expansion
« on: July 29, 2014, 02:58:46 PM »
Maybe this is a bug!?

I discovered it while compiling the pixman library.

Code: [Select]
#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

  • Guest
Re: macro expansion
« Reply #1 on: July 29, 2014, 05:36:22 PM »
Probably.

PellesC will compile the following

Code: [Select]
#define macro(a) bla_##a##_

void bla_12_(void){;}

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

But not with
Code: [Select]
void bla_1_2_(void){;}
VC6 compiles both.

John

Offline frankie

  • Global Moderator
  • Member
  • *****
  • Posts: 2113
Re: macro expansion
« Reply #2 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:
Code: [Select]
#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

  • Guest
Re: macro expansion
« Reply #3 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?