Page 1 of 1

Stupid enum problem....

Posted: Mon Apr 22, 2019 5:59 pm
by Greg Corson
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?

Re: Stupid enum problem....

Posted: Tue Apr 23, 2019 12:14 am
by papaluna
I think the C syntax is

Code: Select all

enum [identifier] {enum-list};

Re: Stupid enum problem....

Posted: Tue Apr 23, 2019 12:54 am
by ESP_Angus
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.

Re: Stupid enum problem....

Posted: Tue Apr 23, 2019 8:24 pm
by Greg Corson
Knew it was something dumb, just noticed the code was compiling as C and not C++.

Thanks for the tip!