Skip to content
Low-level programming · Higher-level thinking
Login Register
Forum / Requests and Feedback

negative value inside enum

A community discussion post from the original code:zIRON forum.

Emil_halim member
Posts
639
Threads
104
Location
Alex, Egypt

negative value inside enum

i have this enum in c

enum BRANCH_TYPE
{
  JO = 1,
  JC,
  JE,
  JA,
  JS,
  JP,
  JL,
  JG,
  JB,
  JECXZ,
  JmpType,
  CallType,
  RetType,
  JNO = -1,
  JNC = -2,
  JNE = -3,
  JNA = -4,
  JNS = -5,
  JNP = -6,
  JNL = -7,
  JNG = -8,
  JNB = -9
};

i changed it to

enum BRANCH_TYPE : int32
{
  JO_ = 1,
  JC_,
  JE_,
  JA_,
  JS_,
  JP_,
  JL_,
  JG_,
  JB_,
  JECXZ_,
  JmpType_,
  CallType_,
  RetType_,
  JNO_ = -1,
  JNC_ = -2,
  JNE_ = -3,
  JNA_ = -4,
  JNS_ = -5,
  JNP_ = -6,
  JNL_ = -7,
  JNG_ = -8,
  JNB_ = -9,
}

but ziron did not allow nigative value inside enum.

so can this be made please.

http://www.freewebs.com/ogremagic/index.htm

Replies

Colin admin
Posts
928
Threads
49
Location
Bulgaria

enum's do not support negative numbers intentionally... because enums are always unsigned

enum BRANCH_TYPE : int32
{
  JO_ = 1,
  JC_,
  JE_,
  JA_,
  JS_,
  JP_,
  JL_,
  JG_,
  JB_,
  JECXZ_,
  JmpType_,
  CallType_,
  RetType_,
}
const JNO_ = -1;
const JNC_ = -2;
const JNE_ = -3;
const JNA_ = -4;
const JNS_ = -5;
const JNP_ = -6;
const JNL_ = -7;
const JNG_ = -8;
const JNB_ = -9;

i may consider adding support for signed at a later date, but progress will be slow for the next month has I have alot of work this coming month or 2.

0CodErr member
Posts
201
Threads
37
Location
Unknown
enum's do not support negative numbers intentionally... because enums are always unsigned
# It is now possible to set the default increment of an enum by passing a parameter to the type.
e.g. enum NAME: DWord (2) { ...

program RAW_IMAGE 'test';

#set bits 32;

enum ENUM_X : Int32 (-4) {X0 = 0, X1, X2, X3, X4}

$echof 'X0 = ', X0;
$echof 'X1 = ', X1;
$echof 'X2 = ', X2;
$echof 'X3 = ', X3;
$echof 'X4 = ', X4;

Result:

X0 = 0 X1 = -4 X2 = -8 X3 = -12 X4 = -16
        Seems currently negative values also supported. 

Then need to add this information in our documentation.

Colin admin
Posts
928
Threads
49
Location
Bulgaria

I will include this in documentation once i complete more of the documentation :P