Name

$MinEnumSize Compiler Directive

Syntax

{$Z1}            // default
{$MinEnumSize 1} // default
{$Z2}
{$Z4}
{$MinEnumSize 2}
{$MinEnumSize 4}
{$Z-} // obsolete, means {$Z1}
{$Z+} // obsolete, means {$Z4}

Scope

Local

Description

The $MinEnumSize compiler directive sets the smallest size (in bytes) that Delphi uses for an enumerated type. The default is 1 byte, which means Delphi uses the size that is most appropriate. An enumeration with up to 256 literals fits in 1 byte, and an enumeration with up to 65,568 literals fits into 2 bytes.

If you have an enumerated type that must be compatible with an enum in a C or C++ program, you can adjust the size of the enumerated type for compatibility. Usually, that means setting the minimum enumeration size to 4.

Example

{$MinEnumSize 4}  // Increase the size for C compatibility.
type
  TCEnum = (cRed, cBlack);
{$MinEnumSize 1} // Restore the default.

function GetColor: TCEnum; external 'cdemo.dll';

See Also

Type Keyword

Get Delphi in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.