This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Compiler/F28M35H52C: enum size and shared memory

Part Number: F28M35H52C

Tool/software: TI C/C++ Compiler

Hello,

I'm facing an issue on my concerto and I am looking for help.
Let's try summarize the issue :)

I want to share an enum between ARM and C28.
This enum is "small" and could be encoded in a char. I "packed" structure to be sure that alignement doesn't hide my problem.
I summarize my code with the simple example following :

#if defined(__TMS320C2000__)
// struct is packed by default on the DSP
#define STRUCT_PACKED
#elif defined(__TI_ARM__)
#define STRUCT_PACKED __attribute__((__packed__))
#endif

typedef enum {
	A,
	B,
	C
} FOO;

struct STRUCT_PACKED test
{
	FOO			enumValue;
	uint16_t	numericValue;
}


By default, the compiler will see this both enum with this size :

  • ARM -> Int -> 32 bit
  • C28 -> Int -> 16 bit
  • NOK, we have here a clear misalignement between the both proc.


Different options seems available about enum on compilers :

  • ARM -> --small_enum
  • ARM -> --enum_type (packed/int)
  • C28 -> did not find any option about enum size, but the strict C89/C99 option.


Admit that I enable one of theses option, what happened ?

ARM compiled with --small_enum enabled :
ARM -> char -> 8 bit
C28 -> Int -> 16 bit
NOK

ARM compiled with --enum_type=int
ARM -> Int -> 32 bit
C28 -> Int -> 16 bit
NOK

ARM compiled with --enum_type=packed
ARM -> Int -> 32 bit
C28 -> Int -> 16 bit
NOK

Is there a "clean" way to compile the both side properly ?
What is your recommandation to handle properly such situations ?

Many thanks !
Cheers,
T.

  • Something similar to this will work ...

    typedef enum {
       A,
       B,
       C,
       unused_limit = 1L << 24
    } FOO;
    

    The enumeration value unused_limit is added merely to establish the size of the type.  It needs to be a positive integer too big for 16-bits, yet fits within 32-bits.  I also suggest you clearly comment the purpose of unused_limit, to avoid it getting removed in the future.

    Thanks and regards,

    -George

  • Many thanks George for your reply.

    I understand the trick, but I do not consider it as "clean" as it request me to add it for each existing enum but also the future ones.

    So you confirm me that no other way exists to force both compilers to be aligned in such situations ?

    Thanks and regards,

    T.

  • Unfortunately, I am not aware of any other method.

    Thanks and regards,

    -George