Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

C-fags

Name: Anonymous 2011-06-25 16:08

What would be the best way to implement flags in C?
Bit-fields, enums, defines, etc. I've seen arguments for all three so I'm asking you, mighty /prog/, to resolve this problem.

inb4 every /prog/ meme in existence

Name: Anonymous 2011-06-25 17:03

>>3,4
[/b]polecat kebabs[/b] to the two of you.

>>2
Alright, so if I had an arbitrary number of conditions some input should satisfy, would it make more sense to do something like this?

prepare for quickly written PIG DISGUSTING code:


#define FLAG1 = 01
#define FLAG2 = 02
#define FLAG3 = 04
// ...

// ...
unsigned char my_flags;
if (some_condition)
   my_flags |= FLAG1 | FLAG2;
if ((my_flags & FLAG1) == FLAG1)
   // FLAG1 high
if ((my_flags & FLAG2) == FLAG2)
   // FLAG2 high
if ((my_flags & FLAG3) == FLAG3)
   // woops, FLAG3 is low


Looks kind of ugly, so I'm wondering if there's a better way.

Name: Anonymous 2011-06-25 17:03

self-fix
polecat kebabs

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List