The following code will compile as C, but not as C ++:
#include <stdio.h>
struct somestruct {
int id;
enum {
STATE1 = 0,
STATE2,
STATE3,
STATE4,
} state;
};
int main(int argc, char *argv[])
{
static struct somestruct s;
if (s.state == STATE1) {
printf("state1\n");
}
return 0;
}
In C ++, I would have to use somestruct::STATE1(because enum declaration is limited by structure / class?). The project I'm working on should be written in C, but we are currently using some C ++ libraries (Arduino), so we compile our c-code using the C ++ compiler. So, is there a way to make the code above in C ++?
source
share