October 30, 2025, 03:23:54 PM

News:

IWBasic runs in Windows 11!


Two issues with #define and #ifdef

Started by Mike Stefanik, February 19, 2006, 10:19:40 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Mike Stefanik

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.

Mike Stefanik
www.catalyst.com
Catalyst Development Corporation

Parker

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.

Ionic Wind Support Team

Already been fixed.  #ifdef now checks for constant definitions too.
Ionic Wind Support Team