#equivalent to C's #if?

1 messages · Page 1 of 1 (latest)

bright swift
#

Is there a way to conditionally select to compile/not compile a bit of code?

#if SOMETHING
printf("bbb")
#else
printf("aaa")
#endif
#

equivalent to C's #if?

fleet trout
#

Zig's normal if and switch will automatically behave like that if the condition is a constant.

bright swift
#

is there a way to ensure it behaves this way?

fleet trout
#

I believe you can make it explicit with if (comptime cond) {} and switch (comptime cond).

#

Though I've not seen much code do that.

bright swift
#

yep! it works, thank you so much

fleet trout
#

You're welcome o7 😄

bright swift
#

i tried doing comptime if before but that was obviously wrong