Skip to main content
gamedev.net
🔒 Locked

flags?

Started by andyZER0 2 replies 300+ views
Original Post
andyZER0
andyZER0
How do I create flags? (i.e. SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO)) I know I have to pass some ints into a function or what not, but how will the program know which flags have been passed? I''m pretty sure LOTS of if statements isn''t very efficient lol (or maybe it is =-o). Thanks in advance.
djsteffey
djsteffey
look into the logical AND (&) and the logical OR (|) operations


"A soldier is a part of the 1% of the population that keeps the other 99% free" - Lt. Colonel Todd, 1/38th Infantry, Ft. Benning, GA
nonpop
nonpop

int const flag1 = (1<<0);
int const flag2 = (1<<1);
int const flag3 = (1<<2);
...
int flags = flag2 | flag3;
...
if (flags & flag1)
{
// flag1 set

}
if (flags & flag2)
{
// flag2 set

}
...

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.