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/MSP430FR5994: static_cast<enum>(int) returns always 0

Part Number: MSP430FR5994

Tool/software: TI C/C++ Compiler

I don't understand why the operator static_cast<color>(1) returns 0 (see the code below).


#include <cstdio>
#include <msp430.h>

/**
 * hello.c
 */

enum class color: unsigned char
{
    red = 1,
    green = 2,
    blue = 4,
};

int main(void)
{
    color c;

    WDTCTL = WDTPW | WDTHOLD;    // stop watchdog timer

    c = color::red;   printf("Red   = %d\r\n", static_cast<int>(c));
    c = color::green; printf("Green = %d\r\n", static_cast<int>(c));
    c = color::blue;  printf("Blue  = %d\r\n", static_cast<int>(c));
    printf("\r\n");

    c = static_cast<color>(1); printf("Red   = %d\r\n", static_cast<int>(c));
    c = static_cast<color>(2); printf("Green = %d\r\n", static_cast<int>(c));
    c = static_cast<color>(4); printf("Blue  = %d\r\n", static_cast<int>(c));
    printf("\r\nEnd\r\n");

    return 0;
}

/*
Console:

Red   = 1
Green = 2
Blue  = 4

Red   = 0
Green = 0
Blue  = 0

End
*/

/*
Compiler version: TI v18.1.4.LTS

Compiler flags:

-vmspx
--data_model=restricted
--use_hw_mpy=F5
--include_path="${CCS_BASE_ROOT}/msp430/include"
--include_path="${PROJECT_ROOT}"
--include_path="${CG_TOOL_ROOT}/include"
--advice:power="1,2,3,4,5.1,5.2,6,7,8,9,10,11,12,13,14,15"
--advice:hw_config=all
--define=__MSP430FR5994__
--define=_MPU_ENABLE
-g
--printf_support=minimal
--diag_warning=225
--diag_wrap=off
--display_error_number
--enum_type=unpacked
--silicon_errata=CPU21
--silicon_errata=CPU22
--silicon_errata=CPU40
*/

/*
Linker flags:

-m"${ProjName}.map"
--heap_size=300
--stack_size=160
--cinit_hold_wdt=on
-i"${CCS_BASE_ROOT}/msp430/include"
-i"${CCS_BASE_ROOT}/msp430/lib/5xx_6xx_FRxx"
-i"${CCS_BASE_ROOT}/msp430/lib/FR59xx"
-i"${CG_TOOL_ROOT}/lib"
-i"${CG_TOOL_ROOT}/include"
--priority
--reread_libs
--define=_MPU_ENABLE
--diag_wrap=off
--display_error_number
--warn_sections
--xml_link_info="${ProjName}_linkInfo.xml"
--use_hw_mpy=F5
--rom_model
*/