Here’s a minimal example of what I’m trying to do:
enum color { RED, GREEN, BLUE };
typedef enum legacy_color enum color;
int
main(void)
{
return 0;
}
Compilation fails with
test.c:13:27: error: two or more data types in declaration specifiers
13 | typedef enum legacy_color enum color;
| ^~~~
test.c:13:32: warning: empty declaration with storage class specifier does not redeclare tag
13 | typedef enum legacy_color enum color;
| ^~~~~
Motivation: I need to rename an enum to align with current naming conventions in my project. The old name needs to remain as an alias, which will be declared in a compatibility header file. Referring back to my example, enum color { RED, GREEN, BLUE }
will be in the main header file, and typedef enum legacy_color enum color
would go in the backward-compatibility header file.
The only other approach I’ve been able to come up with is #define legacy_color color
, but that’s overly broad and would match outside the enum type context.