# Doing it Wrong: Bitmask Edition

• ```
enum {
foo = 0x1;
bar = 0x2;
bat = 0x4;
baz = 0x8;
oof = 0x16;
};
```

Interestingly, this hasn't caused a bug yet.

• Well, I guess if bar and bat (or oof) are never used..., or are always used with oof...

Still, nice!!!

• I must need coffee, it took me too long to catch that WTF.  I'm sitting here thinking "1,2,4,8,16.... what's the problem?" After about 30 seconds, the part about them being Hex finally hit me.  Nice WTF.  The kind that's easy to miss if you aren't paying attention.

• @snoofle said:

Well, I guess if bar and bat (or oof) are never used..., or are always used with oof...

Still, nice!!!

There's no problem with bar or bat. Hex numbers, like decimal numbers, are right-justified, not left-justified. (That is, "int x = 0x1;" is equivalent to "int x = 0x00000001;" even if the latter is more common)

The actual problem is oof: double 0x8 is 0x10, not 0x16

• @curtmack said:

@snoofle said:

Well, I guess if bar and bat (or oof) are never used..., or are always used with oof...

Still, nice!!!

There's no problem with bar or bat. Hex numbers, like decimal numbers, are right-justified, not left-justified. (That is, "int x = 0x1;" is equivalent to "int x = 0x00000001;" even if the latter is more common)

The actual problem is oof: double 0x8 is 0x10, not 0x16

Well, there is if anyone ever uses oof: oof == 0x16 == 0x10 | bar | bat.

• @djork said:

```  enum {
foo = 0x1;
bar = 0x2;
bat = 0x4;
baz = 0x8;
oof = 0x16;
};
```

Interestingly, [b]we haven't found any of the bugs this[/b] caused yet.

FTFY. HTH. HAND.

Of course, if the other parts of the bitmask are also performed incorrectly, such that there's five separate variables, which are somehow considered bitmasks, instead of a single bitmask variable (sounds convoluted, but I've seen people do it), there might not actually be any visible bugs produced - other than an increase in data space.

(Yes, I realize it would be difficult to actually utilize the above code in a non-bitmask manner. However, I've seen it performed. All it takes is the intention to use a union to mirror the structure of the enum, but accidentally say 'struct' instead of 'union'. Note that the code is effectively broken in either case, it's just an interesting variation on exactly how broken it is.)

• @curtmack said:

@snoofle said:

Well, I guess if bar and bat (or oof) are never used..., or are always used with oof...

Still, nice!!!

There's no problem with bar or bat. Hex numbers, like decimal numbers, are right-justified, not left-justified. (That is, "int x = 0x1;" is equivalent to "int x = 0x00000001;" even if the latter is more common)

The actual problem is oof: double 0x8 is 0x10, not 0x16

The other problem is that it breaks the principle of least surprise in the enumeration.. traditionally it goes foo, bar, baz, <...others ...>

•  I personally prefer foo, bar, narf, poit, chez, BOOM - "baz" is so close to "bar" that could be mistaken for "bar"

• @ekolis said:

I personally prefer foo, bar, narf, poit, chez, BOOM - "baz" is so close to "bar" that could be mistaken for "bar"

You forgot egad, zort and troz.  For shame.

• @ekolis said:

I personally prefer foo, bar, narf, poit, chez, BOOM - "baz" is so close to "bar" that could be mistaken for "bar"
If you need anything more than foo and bar, you're doing it wrong.  The third one is foofoo, fourth is foobar, fifth is barfoo, etc.

The BOOM is when your head explodes because you can't remember the difference between foofoofoofoobarfoofoobarbarfoo and  foofoofoofoobarfoofoobarbarbar.

• @belgariontheking said:

If you need anything more than foo and bar, you're doing it wrong.  The third one is foofoo, fourth is foobar, fifth is barfoo, etc.

Only when your using bifoonary. The opening post used quinfoonary and various others were suggested.

•  @cconroy said:

I personally prefer foo, bar, narf, poit, chez, BOOM - "baz" is so close to "bar" that could be mistaken for "bar"

Egad! How could I forget "zort"! (Don't remember "troz" though...)

/me wonders if the "zortrium" armor from Master of Orion is somehow inspired by Pinky & The Brain... or if the "zeon" missiles have anything to do with overheating CPU's...

Actually, there is one that I know of that was done intentionally... not from MOO, but from a Space Empires mod called "Adamant"... there's a "Longhorn Missile" which delivers a virus disabling computer systems aboard an enemy ship!

•  I enjoy my own dialect of flurp zoink knork grets.

• I actually quite like the "barbar" idea.

• @ekolis said:

I personally prefer foo, bar, narf, poit, chez, BOOM - "baz" is so close to "bar" that could be mistaken for "bar"

According to RFC 3092, it is bar, baz, qux, quux, corge, grault, garply, waldo, fred, plugh, xyzzy, thud.

foo, bar, baz, quuux, quuuux, quuuuux, etc. allows an infinite amount of metasyntatic veriables

foo, bar, barfoo, barbar, barfoofoo (binary with foo = 0, bar = 1) also allows an infinite amount.

Zork (Dungeon) mentions Bletch:

```Welcome to Dungeon.                    This version created 1-Oct-94.This is an open field west of a white house with a boarded front door.There is a small mailbox here.A rubber mat saying "Welcome to Dungeon!" lies by the door.>fooWell, FOO, BAR, and BLETCH to you too!>
```

• @ekolis said:

Egad! How could I forget "zort"! (Don't remember "troz" though...)

Pinky remarked somewhere that troz is zort spelt backwards.

I remember reading code made by anime fans, where they'd spend too much time in actually using the names in an accurate manner:

SomeObject goku = gohan.getParent();

Also, "narf" is pretty much everywhere for temp vars, along with "foo" and "bar".

Also, I remember a particular school project on artificial intelligence where the data was in an array called shai_hulud, which would produce a kwisatz_haderach after processing. (Like I said, too much free time!)

Looks like your connection to What the Daily WTF? was lost, please wait while we try to reconnect.