Oxygen Basic
Information => Open Forum => Topic started by: kryton9 on December 22, 2010, 08:04:25 AM
-
I saw this c++ code snippet in a program:
enum
{
ID_IsNotPickable = 0,
IDFlag_IsPickable = 1 << 0,
IDFlag_IsHighlightable = 1 << 1
};
Why wouldn't they just do:
enum
{
ID_IsNotPickable,
IDFlag_IsPickable,
IDFlag_IsHighlightable
};
Both would assign the same values:
ID_IsNotPickable = 0
IDFlag_IsPickable = 1
IDFlag_IsHighlightable = 2
Any ideas why they would use this method? The coder is the guy that wrote the irrlicht engine and he knows his stuff, so there must be a neat reason why he would do this.
-
it looks like, i'm the best!
He isn't good and Irrlicht too!
-
No it doesn't make sense to me either.
But I checked Oxygen's enumeration default value. It starts with 1, but to comply with the C standard I will change it to 0. [forthcoming Alpha024]
Charles
-
it looks like, i'm the best!
He isn't good and Irrlicht too!
hehehehehe that is funny Peter :)
-
No it doesn't make sense to me either.
But I checked Oxygen's enumeration default value. It starts with 1, but to comply with the C standard I will change it to 0. [forthcoming Alpha024]
Charles
I would recommend making it as you have your arrays too Charles. So if they are 0 indexed then enums with 0 would be more consistent in my opinion, or if 1's then that would be fine with me.
-
Kent,
My reason is to read C headers correctly when enumerations are defined. However I would expect most good headers to define the value of first members.
I feel we are committed to a default of indexbase 1 for arrays however. It makes dimensioning and iteration a bit cleaner and also conforms to character indexing in strings.
Charles
PS: you can set the indexbase to any integer value. It is also bound by scope so it can be safely altered within a function without affecting the rest of the program.
-
I go back and forth with 0 and 1 based arrays all the time. Each has their own good qualities. So no worries.