-
Notifications
You must be signed in to change notification settings - Fork 8
Open
Description
#ifndef UndefinedThing; #define UndefinedThing 12; #endif
The above does not work because #ifndef doesn't support ; at the end of lines.
I was hoping to get this working:
#ifndef NotDef
#define NotDef(name) "!(((name) || 1) ?? 0)"
#endif
#ifndef defr
#define defr(name, value) "#if NotDef(name); #define name value; #endif"
#endif
This way I could do my definitions as such:
defr(EliwoodLord, Mercenary)
instead of:
#ifndef EliwoodLord
#define EliwoodLord Mercenary
#endif
But it seems that #if does not support ; either. It does not complain about it as strongly as #ifdef, but this does not work when RoyLord is undefined:
#if NotDef(RoyLord); #define RoyLord 3; #endif
#if NotDef(RoyLord); #define RoyLord 3; #endif
#if NotDef(RoyLord); #define RoyLord 3; #endif
However, this identical version on multiple lines does work when RoyLord is undefined.
#if NotDef(RoyLord)
#define RoyLord 3
#endif
#if NotDef(RoyLord)
#define RoyLord 3
#endif
#if NotDef(RoyLord)
#define RoyLord 3
#endif
They both work when RoyLord is defined.
This feels like the sort of macro / feature that could be built in, so I thought I'd mention it here.
Additionally, I got some weird behaviour while I was trying to get this to work:
This works:
#if NotDef(UndefinedThing); #define asdf "12"; #endif
MESSAGE asdf
But this does not:
#if NotDef(UndefinedThing); #define asdf 12; MESSAGE asdf; #endif
And this infinite loops:
#if NotDef(UndefinedThing); #define asdf 12; MESSAGE asdf; #endif
MESSAGE asdf
I'm possibly doing something in a way that was not intended.
Metadata
Metadata
Assignees
Labels
No labels