Welcome, Guest. Please login or register.

Author Topic: Possible C preprocessor bug in VBCC...  (Read 3218 times)

Description:

0 Members and 1 Guest are viewing this topic.

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16879
  • Country: gb
  • Thanked: 5 times
    • Show all replies
Re: Possible C preprocessor bug in VBCC...
« on: March 29, 2007, 08:06:54 PM »
I think you can get VBCC to show you the emitted C code after the preprocessing stage (just as you can get it to show you the asm before and after going through the instruction scheduler)

I'll give it a try in a few different compilers tomorrow if I get a minute at work ;-)

Quote
Asking this as I want the macro to run on any C compliant compiler


This is a bit of a misnomer really. Macro syntax really isn't anything whatsoever to do with the C language - no more than your favourite macro assembler is anything to do with 68K assembly language ;-)

That said, preprocessor behaviour tends to be well defined in the majority of cases, but I have always been of the opinion that overuse of function-like macros in C is a bad idea.
int p; // A
 

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16879
  • Country: gb
  • Thanked: 5 times
    • Show all replies
Re: Possible C preprocessor bug in VBCC...
« Reply #1 on: March 29, 2007, 08:20:19 PM »
Incidentally, got this from gcc:

macro.c:12:45: pasting "EXTRACTBRCKTELMNT" and "(" does not give a valid preprocessing token


int p; // A
 

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16879
  • Country: gb
  • Thanked: 5 times
    • Show all replies
Re: Possible C preprocessor bug in VBCC...
« Reply #2 on: March 29, 2007, 08:56:42 PM »
Gah, I forgot to say I saw it in both gcc 3.4 and 4.1.
int p; // A
 

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16879
  • Country: gb
  • Thanked: 5 times
    • Show all replies
Re: Possible C preprocessor bug in VBCC...
« Reply #3 on: March 30, 2007, 10:23:14 AM »
Difficult to say if it is a bug or not. It looks like it is, but without a solid preprocessor specification to compare against, I can't say with certainty.

Given this:

#define EXTRACTBRCKTELMNT(Terminator, Elmnt) #Elmnt, #Terminator

#define GETBRCKTELMNT(ToExtract) GETELMNTEXPAND(EXTRACTBRCKTELMNT##ToExtract)
#define GETELMNTEXPAND(a) GETELMNTEXPAND2 (a)
#define GETELMNTEXPAND2(a, b) a, b

let's see a manual expansion:

GETBRCKTELMNT((YYY, XXX))

becomes (expanding GETBRCKTELMNT)

GETELMNTEXPAND(EXTRACTBRCKTELMNT##(YYY, XXX))

becomes (and this is presumably the step it doesnt like)

GETELMNTEXPAND(EXTRACTBRCKTELMNT(YYY, XXX))

becomes (expanding EXTRACTBRCKTELMNT)

GETELMNTEXPAND("YYY", "XXX")

becomes

GETELMNTEXPAND2("YYY", "XXX")

becomes

"YYY", "XXX"

...
int p; // A
 

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16879
  • Country: gb
  • Thanked: 5 times
    • Show all replies
Re: Possible C preprocessor bug in VBCC...
« Reply #4 on: March 30, 2007, 08:56:05 PM »
I couldn't get it to work on any x86 gcc from 3.0 up, it spat out the same error.

That in itself is not necessarily that surprising. Most of the changes over successive versions occur to the compiler itself rather than the preprocessor component.
int p; // A
 

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16879
  • Country: gb
  • Thanked: 5 times
    • Show all replies
Re: Possible C preprocessor bug in VBCC...
« Reply #5 on: March 30, 2007, 09:01:34 PM »
One thing I thought of trying was simply preprocessing the source using cpp from 2.95.3 and then compiling the output in a higher compiler version.

That's not exactly a practical thing to write a decent makefile for, though.
int p; // A