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/DRA712: ENUM Size

Part Number: DRA712


Tool/software: TI C/C++ Compiler

Team

We are using the following SDK Linux Automotive 3.02.00.03 to develop an DRA721, M4-IPU1 application, which one has to an IPC to A15

  • bios_6_52_00_12
  • gcc version 6.3.1 20170215 (release) [ARM/embedded-6-branch revision 245512] (GNU Tools for ARM Embedded Processors 6-2017-q1-update

We define a set of enum for a custom A15-M4 protocol over standard TI IPC methods.

We realize that gcc for A15 set ENUM size to int size, but gcc  for M4 set it to 1byte

typedef enum  sig {NIGHT_MODE=0, PARKING_MODE, SPEED, REVERSE_GEAR} Signal_type;

sizeof(Signal_type); //1 byte

How can we set M4 compiler ENUM size to be compatible with A15 ENUM size?

Regards

  • I don't understand all the details of your problem.  But I think I can shed some light on general techniques for controlling the size of enum types.

    There are two basic methods.  One is command line options, and the other is adding an enumerator with an explicit value that can only fit in the desired size.

    To see all the command line options for any GCC compiler, use the options -v --help.  Capture that in a file and search it for options related to enum types.  I could only find options which appear to reduce the size of enum types.  If you can't rebuild the A15 code, then this is not useful for you.

    As to the second technique, here is an example ...

    #include <limits.h>       /* for INT_MAX */
    
    typedef enum  sig {
       NIGHT_MODE=0,
       PARKING_MODE, 
       SPEED,
       REVERSE_GEAR,
       NEVER_USED = INT_MAX   /* force sizeof(enum) == sizeof(int) */
    } Signal_type;

    Note the addition of the enumerator value NEVER_USED.

    Thanks and regards,

    -George