Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

define if undefined macro / command #64

Open
Veslyquix opened this issue Oct 31, 2024 · 1 comment
Open

define if undefined macro / command #64

Veslyquix opened this issue Oct 31, 2024 · 1 comment

Comments

@Veslyquix
Copy link

Veslyquix commented Oct 31, 2024

#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.

@Crazycolorz5
Copy link
Member

#ifndef UndefinedThing; #define UndefinedThing 12; #endif

This definitely seems like a parser issue. Reminder to myself to look into it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants