FAQ: What types does VisualDSP++ compiler use to implement enumerations and enumeration constants? 

Document created by StuartS Employee on Mar 16, 2010Last modified by CraigG on May 8, 2012
Version 2Show Document
  • View in full screen mode

Q.

What types does VisualDSP++ compiler use to implement enumerations and enumeration constants? 

 

------------------------------------------------------

A.

The VisualDSP++ compiler by default implement the underlying type for enumerations as the first type from the following list that can be used to represent all the values in the specified enumeration : int, unsigned int, long, unsigned long, long long, unsigned long long. If int, long or long long are suitable and there are no negative enumerations constant values the unsigned type for the same size is selected (i.e. unsigned int rather than int). Enumeration constant values can be any integral type including long long and unsigned long long (except for VisualDSP++ 5.0 and earlier SHARC or 21XX compilers as they don't support long long types).

 

Enumerations types being implemented as long long or unsigned long long types is an Analog Devices extension to ANSI C89 standard (ISO/IEC 9899:1990). Allowing enumerations constants to be integral types other than int is an Analog Devices extension to the ANSI C89 and ANSI C99 (ISO/IEC 9899:1999) standards. These extensions can be disabled by using the -enum-is-int switch.

 

When -enum-is-int is used the compiler issues error cc0066 "enumeration value is out of "int" range" when it encounters enumeration constant values that cannot be held using an int type. Warning cc1661 "enumeration value is greater than int type" is issued when larger than int type enumeration values are used and not compiling with the -enum-is-int switch.

 

The different underlying types used by the compiler to implement enumerations can give rise to other compiler warnings. For example in the following enumeration the underlying type will be unsigned int which will result in warning cc0186 "pointless comparison of unsigned integer with zero".

 

typedef enum { v1, v2 } e1;

 

void check (e1 v) {
   if(v < 0)  /* pointless comparison if enumeration type is unsigned */
      printf("foo out of range!");
}

 

If a negative enumeration constant was added to the definition of e1 or if the example was compiled with the -enum-is-int switch the underlying type used will be signed int and there would be no warning issued for the comparison.

Attachments

    Outcomes