Main Content

Enum type definition (-enum-type-definition)

Specify how to represent an enum with a base type

Description

Allow the analysis to use different base types to represent an enumerated type, depending on the enumerator values and the selected definition. When using this option, each enum type is represented by the smallest integral type that can hold its enumeration values.

This option is available on the Target & Compiler node in the Configuration pane.

Set Option

User interface (desktop products only): In your project configuration, the option is on the Target & Compiler node.

User interface (Polyspace Platform, desktop products only): In your project configuration, the option is in the Edit Processor window. This window can be opened from the Target & Compiler node in the Build tab. See Processor Details.

Command line and options file: Use the option -enum-type-definition. See Command-Line Information.

Why Use This Option

Your compiler represents enum variables as constants of a base integer type. Use this option so that you can emulate your compiler.

To check your compiler settings:

  1. Compile this code using the compiler settings that you typically use:

    enum { MAXSIGNEDBYTE=127 } mysmallenum_t;
    
    int dummy[(int)sizeof(mysmallenum_t) - (int)sizeof(int)];
    
    If compilation fails, you have to use one of auto-signed-first or auto-unsigned-first.

  2. Compile this code using the compiler settings that you typically use:

    #include <limits.h>
    
    enum { MYINTMAX = INT_MAX } myintenum_t;
    
    int dummy[(MYINTMAX + 1) < 0 ? -1:1];
    

    If compilation fails, use auto-signed-first for this option, otherwise use auto-unsigned-first.

Settings

Default: defined-by-compiler

defined-by-compiler

Uses the signed integer type for all compilers except gnu, clang and tasking.

For the gnu and clang compilers, it uses the first type that can hold all of the enumerator values from this list: unsigned int, signed int, unsigned long, signed long, unsigned long long and signed long long.

For the tasking compiler, it uses the first type that can hold all of the enumerator values from this list: char, unsigned char, short, unsigned short, int, and unsigned int.

auto-signed-first

Uses the first type that can hold all of the enumerator values from this list: signed char, unsigned char, signed short, unsigned short, signed int, unsigned int, signed long, unsigned long, signed long long, and unsigned long long.

auto-unsigned-first

Uses the first type that can hold all of the enumerator values from these lists:

  • If enumerator values are positive: unsigned char, unsigned short, unsigned int, unsigned long, and unsigned long long.

  • If one or more enumerator values are negative: signed char, signed short, signed int, signed long, and signed long long.

Command-Line Information

Parameter: -enum-type-definition
Value: defined-by-compiler | auto-signed-first | auto-unsigned-first
Default: defined-by-compiler
Example (Bug Finder): polyspace-bug-finder -enum-type-definition auto-signed-first
Example (Code Prover): polyspace-code-prover -enum-type-definition auto-signed-first
Example (Bug Finder Server): polyspace-bug-finder-server -enum-type-definition auto-signed-first
Example (Code Prover Server): polyspace-code-prover-server -enum-type-definition auto-signed-first