Overview

Enumerated types allow users to couple human readable names with numeric values. When an enumeration is defined, Hex Workshop allows you to view and work with the human readable names within the editing environment.

Enumerated types are defined similarly to structures. The general form begins with the "enum" keyword, followed by the enumeration name, an opening brace "{", enumeration definitions, a closing brace "}", and a trailing semicolon ";". Enumeration values may be specified in decimal or hex.  To specify an enumeration value in hex, prefix the hex value with "0x".

enum <ENUM_NAME>

{

  <ENUM_DEFINITIONS>

};

typedef enum <ENUM_NAME>
{
  <ENUM_DEFINITIONS>
} <ENUM_NAME>;

Controlling Enumeration sign and size

The sign and size of the enumeration is control through the #pragma enumsign and #pragma enumsize Library Settings.

Using Enumerations as Constants

Users can use enumerations as constants where an expression is expected.  See the __verify statement at the end of the example:

#pragma enumsize(4)

#pragma enumsign("unsigned")

typedef enum tagSIGNATURE

{

    LocalFileHeader                    = 0x04034B50,

    ArchiveExtraData                   = 0x08064B50,

    EndOfCentralDirectory              = 0x06054B50,

    DigitalSignature                   = 0x05054B50,

    CentralDirectoryFileHeader         = 0x02014B50,

    ZIP64EndOfCentralDirectory         = 0x06064B50,

    ZIP64EndOfCentralDirectoryLocator  = 0x07064B50

} SIGNATURE ;

 

struct LocalFileHeader

{

    SIGNATURE Signature ;

    WORD VersionNeededToExtract ;

    WORD GeneralPurposeBitFlag ;

    COMPRESSION_METHOD CompressionMethod ;

    DOSTIME LastModFileTime ;

    DOSDATE LastModFileDate ;

    DWORD Crc32 ;

    DWORD CompressedSize ;

    DWORD UncompressedSize ;

    WORD  FileNameLength ;

    WORD  ExtraFieldLength ;

    char  FileName[FileNameLength] ;

    blob  ExtraField[ExtraFieldLength] ;

    blob  FileData[CompressedSize] ;

    __verify(Signature == SIGNATURE.LocalFileHeader) ;

} ;

The enumeration is referenced using the <enumeration name>.<enumeration field>.

Examples

enum _FINDEX_SEARCH_OPS

{

  FindExSearchNameMatch,          // Value: 0

  FindExSearchLimitToDirectories, // Value: 1

  FindExSearchLimitToDevices,     // Value: 2

  FindExSearchMaxSearchOp         // Value: 3

};

 

enum myOtherExample

{

  MY_STARTING_VALUE = 100, // Value: 100

  MY_NEXT_VALUE_1,         // Value: 101

  MY_NEXT_VALUE_2,         // Value: 102

  MY_RESET_VALUE = 200,    // Value: 200

  MY_NEXT_VALUE_3,         // Value: 203

  MY_OTHER_VALUE  = 0x10   // Value: 16

};

More Information on Structure Definitions

Definition Overview, Data Types, Enumerated Types, Arrays, Strings, Bitfields, Expressions, Conditionals, Functions, Verification, Library Settings, Structure Settings, and Reserved Words and Symbols.