This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Compiler/TMS320F28335: Issue on automatic "Enum" definition by the compiler

Part Number: TMS320F28335

Tool/software: TI C/C++ Compiler

Hello,

I'm using CCSV8 with V18.1.0 compiler.

In my program, I have some declared "enum" with only superior or equal to 0 values. So, the compiler defines automatically the "enum" as an UNSIGNED INT, isn't it?

But, according to my specifications, I have to test if the first value is well superior or equal to 0.

For all of this tests, the compiler displays a WARNING because the test is already right.

My question is: is it possible to disable the automatic definition of the "enum" and always treat "enum" as INT on the compiler (even if the first "enum" value is equal to 0)?

Thank you very much.

Best Regards,

Alexandre.

  • Please see the section titled Size of Enum Types in the C28x compiler manual.  If that does not answer your question, then for one source file which shows this ...

    Alexandre Contrepois said:
    the compiler displays a WARNING because the test is already right.

    ... please submit a test case as described in the article How to Submit a Compiler Test Case.

    Thanks and regards,

    -George

  • Hello George,

    (just for information, there is a mistake in my sentence "the compiler displays a WARNING because the test is always right.", sorry).

    I already read this section in the compiler manual and I have understood that the type of all "enum" values is defined according to the first value

    And my question was just to know if there is a compiler option to disable this automatic definition of "enum" values and if it's possible to pre-define a type for all "enum" declaration.

    For example: typedef enum{ VALUE1 = 0, VALUE2, VALUE3}Values

        with VALUE1/VALUE2/VALUE3 defines as "INT" and not "UNSIGNED INT".

    In this case, the WARNING coming from a test always right (VALUE2 >= 0) would disappear. This is what I want.

    Do you have a solution please?

    Thank you very much for your support.

    Best Regards,

    Alexandre.

       

  • George Mock said:
    ... please submit a test case as described in the article How to Submit a Compiler Test Case.

    The following can demonstrate the warning:

    #include <stdbool.h>
    
    typedef enum
    {
        VALUE0,
        VALUE1,
        VALUE2
    } values_t;
    
    values_t the_value = VALUE1;
    
    bool validate (const values_t value)
    {
        return (value >= VALUE0) && (value <= VALUE2);
    }
    
    int main(void)
    {
        return validate (the_value);
    }

    1) If compile using ti-cgt-c2000_18.1.2.LTS with --relaxed_ansi then get a warning which suggests values_t has been given an unsigned type:

    Invoking: C2000 Compiler
    "/home/mr_halfword/ti/ccs810/ccsv8/tools/compiler/ti-cgt-c2000_18.1.2.LTS/bin/cl2000" -v28 -ml -mt --float_support=fpu32 --include_path="/home/mr_halfword/workspace_v8/C2000_enum_type" --include_path="/home/mr_halfword/ti/ccs810/ccsv8/tools/compiler/ti-cgt-c2000_18.1.2.LTS/include" -g --c99 --relaxed_ansi --diag_warning=225 --diag_wrap=off --display_error_number --preproc_with_compile --preproc_dependency="main.d_raw"  "../main.c"
    "../main.c", line 14: warning #188-D: pointless comparison of unsigned integer with zero
    Finished building: "../main.c"

    2) Whereas if compile using --strict_ansi don't get the warning:

    Invoking: C2000 Compiler
    "/home/mr_halfword/ti/ccs810/ccsv8/tools/compiler/ti-cgt-c2000_18.1.2.LTS/bin/cl2000" -v28 -ml -mt --float_support=fpu32 --include_path="/home/mr_halfword/workspace_v8/C2000_enum_type" --include_path="/home/mr_halfword/ti/ccs810/ccsv8/tools/compiler/ti-cgt-c2000_18.1.2.LTS/include" -g --c99 --strict_ansi --diag_warning=225 --diag_wrap=off --display_error_number --preproc_with_compile --preproc_dependency="main.d_raw"  "../main.c"
    Finished building: "../main.c"

    My reading of section 6.4.1 Size of Enum Types from SPRU514P is that for both non strict ANSI and strict ANSI modes the (signed) "int" type should be chosen before "unsigned int", assuming the enumeration values fit into an int.

  • To Chester Gillon ... Thank you for that test case.

    To  Alexandre Contrepois ... You have never showed us exactly which warning you see.  Thus, I remain concerned that the warning in the test case from Chester is not the same one.  I'd appreciate if you would submit the test case I requested earlier.  Or, at least confirm whether the warning in Chester's test case is a match.

    Thanks and regards,

    -George

  • To George, thank you for your example, this is exactly the same warning (I use the -relaxed_ansi).

    To both of you, "the_value" is defined as an unsigned type automatically because the "enum" starts at 0 (by default).

    So, the test "value >= VALUE0" is always right and the compiler displays the WARNING: "pointless comparison...".

    What I want is to never have this WARNING without changing the program, but adjusting the compiler options to have something like: all "enum" are defined as "int" by default (even if it starts at 0)

    Do you see what I mean?

    Thank you for your support guys.

    Best Regards,
    Alexandre.
  • Alexandre Contrepois said:
    What I want is to never have this WARNING without changing the program, but adjusting the compiler options to have something like: all "enum" are defined as "int" by default (even if it starts at 0)

    You can do that by compiling with the option --strict_ansi.  However, there is a good chance that using this option will cause you problems in some other completely unrelated part of your code.  

    That's why I think the best solution is to change your code, though not much.  Just add one line ...

    typedef enum
    {
        never_used = -1,  /* addition */
        VALUE0,
        VALUE1,
        VALUE2
    } values_t;

    By adding the never_used enumeration value, and making it -1, you force the compiler to use type int for this enum.  

    Thanks and regards,

    -George

  • Hello George,

    This is exactly what we did until now to avoid this WARNING. 

    So I understand that there is no possibility to disable or change the way to automatically define the type of "enum" value. 

    Thank you for your support, it answers my question !

    Best regards,

    Alexandre.