主要内容

枚举类型定义 (-enum-type-definition)

指定如何用基类型表示 enum

描述

允许分析操作使用不同的基类型来表示枚举类型,具体取决于枚举器值和所选的定义。使用此选项时,每个 enum 类型由可以容纳其枚举值的最小整数类型来表示。

此选项位于配置窗格中的目标和编译器节点上。

设置选项

使用以下方法之一设置选项:

  • Polyspace® 用户界面(仅限桌面端产品):在您的工程配置中,选择目标和编译器节点,然后为此选项选择一个值。

  • Polyspace 平台用户界面(仅限桌面端产品):在您的工程配置中,在编译选项卡上,选择目标和编译器,然后为处理器选项配置设置。在编辑处理器对话框中,为枚举的基础类型选项选择一个值。有关详细信息,请参阅处理器详细信息

  • 命令行和选项文件:请使用 -enum-type-definition 选项。请参阅命令行信息

为何使用此选项

编译器将 enum 变量表示为基整数类型的常量。使用此选项可以模拟您的编译器。

要检查您的编译器设置:

  1. 请使用您常用的编译器设置编译以下代码:

    enum { MAXSIGNEDBYTE=127 } mysmallenum_t;
    
    int dummy[(int)sizeof(mysmallenum_t) - (int)sizeof(int)];
    
    如果编译失败,则您必须使用 auto-signed-firstauto-unsigned-first

  2. 请使用您常用的编译器设置编译以下代码:

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

    如果编译失败,请为此选项使用 auto-signed-first,否则请使用 auto-unsigned-first

设置

默认值: defined-by-compiler

defined-by-compiler

对除了 gnu、clang 和 tasking 之外的所有编译器使用有符号整数类型。

对于 gnu 和 clang 编译器,它将使用以下列表中第一个可以容纳所有枚举器值的类型:unsigned intsigned intunsigned longsigned longunsigned long longsigned long long

对于 tasking 编译器,它使用以下列表中第一个可以容纳所有枚举器值的类型:charunsigned charshortunsigned shortintunsigned int

auto-signed-first

使用以下列表中第一个可以容纳所有枚举器值的类型:signed charunsigned charsigned shortunsigned shortsigned intunsigned intsigned longunsigned longsigned long longunsigned long long

auto-unsigned-first

使用以下列表中第一个可以容纳所有枚举器值的类型:

  • 如果枚举器值为正:unsigned charunsigned shortunsigned intunsigned longunsigned long long

  • 如果一个或多个枚举器值为负:signed charsigned shortsigned intsigned longsigned long long

命令行信息

参数:-enum-type-definition
值:defined-by-compiler | auto-signed-first | auto-unsigned-first
默认值:defined-by-compiler
示例 (Bug Finder):polyspace-bug-finder -enum-type-definition auto-signed-first
示例 (Code Prover):polyspace-code-prover -enum-type-definition auto-signed-first
示例 (Bug Finder Server):polyspace-bug-finder-server -enum-type-definition auto-signed-first
示例 (Code Prover Server):polyspace-code-prover-server -enum-type-definition auto-signed-first