Stupid enum problem....

Greg Corson
Posts: 35
Joined: Sun May 20, 2018 9:16 pm

Stupid enum problem....

Postby Greg Corson » Mon Apr 22, 2019 5:59 pm

Ok, maybe I'm being dense but this statement:

enum command_id:uint8_t {BMI160TELEMETRY = 1, MPU9250TELEMETRY};

Compiles ok in ESP32 arduino but fails when I compile it under ESP-IDF with the following error

C:/msys32/home/gcorson/esp/tcp_server/main/tcp_server.c:31:16: error: expected identifier or '(' before ':' token enum command_id:uint8_t {BMI160TELEMETRY = 1, MPU9250TELEMETRY};

Not clear why this happens, isn't enum's syntax supposed to be

enum [identifier] [: type] {enum-list};

What am I doing wrong?

papaluna
Posts: 50
Joined: Tue Jan 30, 2018 11:27 am

Re: Stupid enum problem....

Postby papaluna » Tue Apr 23, 2019 12:14 am

I think the C syntax is

Code: Select all

enum [identifier] {enum-list};
--
Paul.

ESP_Angus
Posts: 1919
Joined: Sun May 08, 2016 4:11 am

Re: Stupid enum problem....

Postby ESP_Angus » Tue Apr 23, 2019 12:54 am

Hi Greg,

Typed enums are a C++ feature added in C++11.

You will need to either remove the ": uint8_t" part (without this specified type, in both C & C++ the enum values will have the type of int, ie 4 bytes wide not 1 byte wide), or compile this code as C++ not C.

Greg Corson
Posts: 35
Joined: Sun May 20, 2018 9:16 pm

Re: Stupid enum problem....

Postby Greg Corson » Tue Apr 23, 2019 8:24 pm

Knew it was something dumb, just noticed the code was compiling as C and not C++.

Thanks for the tip!

Who is online

Users browsing this forum: Bing [Bot], lotharyx and 14 guests