Jump to content

Just wondering...


  • You cannot reply to this topic

3 replies to this topic

#1 Marcin

Marcin

    UberGames Developer

  • UberGames Developer
  • 688 posts

Posted 27 March 2008 - 09:10 AM

Why the hell are binary flags in the Q3/EF source code defined like this:

#define	BLAH_FLAG1	0x00000001
#define	BLAH_FLAG2	0x00000002
#define	BLAH_FLAG3	0x00000004
#define	BLAH_FLAG4	0x00000008
#define	BLAH_FLAG5	0x00000010
#define	BLAH_FLAG6	0x00000020
#define	BLAH_FLAG7	0x00000040
#define	BLAH_FLAG8	0x00000080
#define	BLAH_FLAG9	0x00000100	// etc...

Personally, I think this is a lot more consistent (and more common):
enum flags {
	BLAH_FLAG1 = 1 << 0,
	BLAH_FLAG2 = 1 << 1,
	BLAH_FLAG3 = 1 << 2,
	BLAH_FLAG4 = 1 << 3,
	BLAH_FLAG5 = 1 << 4,
	BLAH_FLAG6 = 1 << 5,
	BLAH_FLAG7 = 1 << 6,
	BLAH_FLAG8 = 1 << 7,
	BLAH_FLAG9 = 1 << 8
};
Although it doesn't matter a lot because C doesn't do type checking with these things :)

#2 TiM

TiM

    Administrator

  • UberGames Admin
  • 3,425 posts

Posted 27 March 2008 - 10:29 AM

Hahah that's Carmack's world there. Most of it probably wasn't meant to be understood by the standard human.... :P

Hmmmm........

The only thing I can think of is that one is the direct number, whereas the other one is an equation that must be solved to derive the final value.

Ultimately, they'd be the same in the final code, so maybe it's something involving the compiler. Perhaps computers of that day were so slow compiling the code, anything would be done to speed up pre-processing.....

Either that, or it was just thought the other way looked nicer haha.... :)

-TiM

#3 Marcin

Marcin

    UberGames Developer

  • UberGames Developer
  • 688 posts

Posted 28 March 2008 - 07:30 PM

Yes but there's still no reason for not using enums >:).

#4 TiM

TiM

    Administrator

  • UberGames Admin
  • 3,425 posts

Posted 29 March 2008 - 02:51 AM

But is there more a reason to use enums instead?

I'm not sure, but I think defines are handled differently on compile time then enums... >:)

-TiM



0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users