C - check if two rewrites are synchronized at compile time

The problem is that I have two enumerations in two different files that must have the same sets of constants (two different processes are generated by two files along with other files). I want the enums to be in sync, that is, when someone adds a new value to enum x and forgets to update another enum, I want to throw a compilation error. Is it possible?

+5
source share
6 answers

Why don't you put this ad in one header file and then include it in the two locations you need?

+11
source

, LAST_ENUM_1 LAST_ENUM_2. #if , .

#if LAST_ENUM_1 != LAST_ENUM_2
   #error Enums have different sizes
#endif
+5

, , ...

, perl script, , , , perl script makefile. , , .

+1

, , , : , - - , .

( ) ( ). , .

0

enum EMyEnum
{
    JOE   = 0,
    BLACK = 1,
    WHITE = 2,

    END_OF_ENUM = 3
}

, ,

0

( , TU) , TU TU, .

You need to fix everything so that you have one copy of the enumeration definition that is used by both programs, so it belongs to the header that is included by both. Almost everything else is too error-prone for comfort.

0
source

All Articles