Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I'm reading open source code (C++) and can't figure out why they put enum this way

Tags:

I found enum be defined like this and can't figure it out why they put leading zero there.

enum SquareDelta {   DELTA_SSW = -021,   DELTA_SS = -020,   DELTA_SSE = -017,   DELTA_SWW = -012,   DELTA_SW = -011,   DELTA_S = -010,   DELTA_SE = -07,   DELTA_SEE = -06,   DELTA_W = -01,   DELTA_ZERO = 0,   DELTA_E = 01,   DELTA_NWW = 06,   DELTA_NW = 07,   DELTA_N = 010,   DELTA_NE = 011,   DELTA_NEE = 012,   DELTA_NNW = 017,   DELTA_NN = 020,   DELTA_NNE = 021 }; 

I guess this is not just normal int enum but what is it? could it be in hex like number beginning with "0x" ?

like image 794
Oreo23 Avatar asked Aug 17 '11 16:08

Oreo23


People also ask

Why do we use enum in C?

Enumeration or Enum in C is a special kind of data type defined by the user. It consists of constant integrals or integers that are given names by a user. The use of enum in C to name the integer values makes the entire program easy to learn, understand, and maintain by the same or even different programmer.

Why is enum not good?

They Lack Accountability. To be clear, it's a mistake to assume consensual non monogamy is void of commitment. It's not simply informing your casual hookup of your other casual hookups. For a lot of people, it's being communicative to their partner of what they're doing with their friend with benefits or boyfriend.

What's the idea behind an enum?

An enum is a data type that contains fixed set of constants. An enum is just like a class , with a fixed set of instances known at compile time. Advantages of enum: enum improves type safety at compile-time checking to avoid errors at run-time.


1 Answers

Those numbers are octal constants. (Numbers leading with 0 but not 0x are considered in base-8).

Thus, -021 == -17, -020 = -16, etc.

like image 82
yan Avatar answered Sep 24 '22 19:09

yan