This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

cpp - error: #29: expected an expression

Hello, I am quite new to C/C++ and Keil. I am using the following:

nrf52832_xxaa (Cortex M4)
Keil uVision 5.24.2.0

I have some existing C++ code which I had used on another project and am looking to implement it on the nrf52. However I am having problems with using Keil and C++. Specifically, on the definition of a struct, as shown below:

    const nrf_drv_twi_config_t twi_lm75b_config = {
       .scl                = ARDUINO_SCL_PIN,
       .sda                = ARDUINO_SDA_PIN,
       .frequency          = NRF_TWI_FREQ_100K,
       .interrupt_priority = APP_IRQ_PRIORITY_HIGH,
       .clear_bus_init     = false
    };

I am getting the following errors:

*** Using Compiler 'V5.06 update 5 (build 528)', folder: 'C:\Keil_v5\ARM\ARMCC\Bin'
Build target 'nrf52832_xxaa'
compiling main.cpp...
..\..\..\main.cpp(153): error:  #29: expected an expression
         .scl                = ARDUINO_SCL_PIN,
..\..\..\main.cpp(154): error:  #29: expected an expression
         .sda                = ARDUINO_SDA_PIN,
..\..\..\main.cpp(155): error:  #29: expected an expression
         .frequency          = NRF_TWI_FREQ_100K,
..\..\..\main.cpp(156): error:  #29: expected an expression
         .interrupt_priority = APP_IRQ_PRIORITY_HIGH,
..\..\..\main.cpp(157): error:  #29: expected an expression
         .clear_bus_init     = false
..\..\..\main.cpp(121): warning:  #177-D: function "data_handler"  was declared but never referenced
  __STATIC_INLINE void data_handler(uint8_t temp)
..\..\..\main.cpp: 1 warning, 5 errors
".\_build\nrf52832_xxaa.axf" - 5 Error(s), 1 Warning(s).
Target not created.

I have tried simplifying the case down and declaring the struct in the main.cpp,

typedef struct
{
    bool            peeled;                 ///< SCL pin number.
} apple;

void test_init (void)
{
    const apple red = {
       .peeled = true
    };
}

but the same problem occurs

*** Using Compiler 'V5.06 update 5 (build 528)', folder: 'C:\Keil_v5\ARM\ARMCC\Bin'
Build target 'nrf52832_xxaa'
compiling main.cpp...
..\..\..\main.cpp(175): error:  #29: expected an expression
         .peeled = true
..\..\..\main.cpp(121): warning:  #177-D: function "data_handler"  was declared but never referenced
  __STATIC_INLINE void data_handler(uint8_t temp)
..\..\..\main.cpp: 1 warning, 1 error
".\_build\nrf52832_xxaa.axf" - 1 Error(s), 1 Warning(s).
Target not created.
Build Time Elapsed:  00:00:00

I have included my compiler settings here: https://ibb.co/imk6HG

Any help on this would be greatly appreciated

  • In addition, I have attached my compiler control string:

    --c99 -c --cpu Cortex-M4.fp -D__EVAL -g -O2 --apcs=interwork --split_sections -I ../../../config -I ../../../../../../components -I ../../../../../../components/boards -I ../../../../../../components/drivers_nrf/common -I ../../../../../../components/drivers_nrf/delay -I ../../../../../../components/drivers_nrf/hal -I ../../../../../../components/drivers_nrf/nrf_soc_nosd -I ../../../../../../components/drivers_nrf/twi_master -I ../../../../../../components/drivers_nrf/uart -I ../../../../../../components/libraries/atomic -I ../../../../../../components/libraries/balloc -I ../../../../../../components/libraries/bsp -I ../../../../../../components/libraries/experimental_log -I ../../../../../../components/libraries/experimental_log/src -I ../../../../../../components/libraries/experimental_memobj -I ../../../../../../components/libraries/experimental_section_vars -I ../../../../../../components/libraries/strerror -I ../../../../../../components/libraries/util -I ../../../../../../components/toolchain -I ../../.. -I ../../../../../../external/fprintf -I ../../../../../../external/segger_rtt -I ../config -I ../../../../../../components/drivers_nrf/rtc -I ../../../../../../components/drivers_nrf/clock -I ../../../../../../components/libraries/timer
    -I./RTE/_nrf52832_xxaa
    -IC:/Keil_v5/ARM/PACK/ARM/CMSIS/4.5.0/CMSIS/Include
    -IC:/Keil_v5/ARM/PACK/NordicSemiconductor/nRF_DeviceFamilyPack/8.15.0/Device/Include
    -D__UVISION_VERSION="524" -D_RTE_ -DNRF52 -DBOARD_PCA10040 -DBSP_DEFINES_ONLY -DCONFIG_GPIO_AS_PINRESET -DFLOAT_ABI_HARD -DNRF52 -DNRF52832_XXAA -DNRF52_PAN_74
    -o .\_build\*.o --omf_browse .\_build\*.crf --depend .\_build\*.d
    

  •     const nrf_drv_twi_config_t twi_lm75b_config = {
           .scl                = ARDUINO_SCL_PIN,
           .sda                = ARDUINO_SDA_PIN,
           .frequency          = NRF_TWI_FREQ_100K,
           .interrupt_priority = APP_IRQ_PRIORITY_HIGH,
           .clear_bus_init     = false
        };
    

    You are trying to initialise the fields of a struct using designated initialisers - but these are not supported in C++

    stackoverflow.com/.../why-does-c11-not-support-designated-initializer-lists-as-c99