IonicWind Software

Aurora Compiler => General Discussion => Topic started by: Mike Stefanik on February 19, 2006, 10:19:40 AM

Title: Two issues with #define and #ifdef
Post by: Mike Stefanik on February 19, 2006, 10:19:40 AM
I found a problem, probably related to how #ifdef and #define are handled internally. If you have code that looks like this:


#define FOOBAR

// some code here

#ifdef FOOBAR

// lots of code here

#endif // FOOBAR


That works just fine. However, make this change:


#define FOOBAR 1

// some code here

#ifdef FOOBAR

// lots of code here

#endif // FOOBAR


Simply defining FOOBAR with a value causes two problems. First, you'll get the error "Unexpected EOF found, missing $endif" (which in of itself seems pretty odd) but you can make it go away by removing the "// FOOBAR" comment at the end of the #endif. However, the second problem is that even though removing the comment allows it to compile, the #ifdef test fails incorrectly (as if FOOBAR is not defined, when it clearly is).

My guess would be that "#define FOOBAR" without a value puts it in a table of defined values, while "#define FOOBAR 1" is some kind of alias for the "const" statement and it's never added to that table.

In a related question, are there plans to implement #if? It would be nice to do something like this:


#define MYPRODUCTBUILD 2415

#if MYPRODUCTBUILD > 2000
#define FOO 123456
#define BAR 987654
#else
#if MYPRODUCTBUILD > 3000
#define FOO 456789
#define BAR 214365
#endif
#endif


While not something that's absolutely essential, it does make conditional compiles based on things like the product version number or feature set easier.

Title: Re: Two issues with #define and #ifdef
Post by: Parker on February 19, 2006, 11:49:28 AM
I don't know how much you would get out of it, but look in the yacc file for the parser and see the implementation of #define vs const. If the #define has an argument, it puts that into the const table, so #ifdef can't find it. #if and #el[se]if would be nice to have too ;). I've been thinking of writing an external preprocessor for fun - it would be much more capable than the current one since it would run outside the parser, it could have macros and advanced #defines, a couple of things would have to belong in Aurora's preprocessor though.

The const alias needs to be fixed, and I'm sure it will. I believe, although I'm not sure, that the #endif token requires that it be at the end of the line. That should be fixed too, I think.
Title: Re: Two issues with #define and #ifdef
Post by: Ionic Wind Support Team on February 19, 2006, 12:31:41 PM
Already been fixed.  #ifdef now checks for constant definitions too.