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.
This kind of code generates warning cc1661 on VisualDSP 5.0 Update 6.
typedef enum{ V1 = 0xFFFFFFF8UL, V2 = 0xFFFFFFFCUL, V3 = 0xFFFFFFFEUL, V4 = 0xFFFFFFFFUL} TV;
It looks to me like a bug when I read this "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".
The warning is intended to identify where the underlying type of an enum is not a signed int type, and in your case it's unsigned long so that is why it is issued. Having looked at this again, we can see that the warning text may have led you to believe that the underlying type was a long long type, i.e. a type with size greater than int, but that's not the case. We will change the warning text to make it clearer, perhaps as follows:
cc1661: {D} warning: enumeration value requires an underlying enumeration type that isn't a signed int.
Regards,
Stuart.
If you decide that you are happy with the compiler using a non-int type, remembering that it may be non-portable and maybe less optimal, then you can suppress the warning. Warnings can be suppressed using the "-Wsuppress 1661" switch or with using #pragma diag support.
Thanks for the response !!
So if values are too big for a signed int, there would be no way to remove this warning ?
Or is there a way to explicitely tell to the compiler the enumeration underlying type to use ? And so, to remove the warning given by the compiler.
Ok !!
Thanks Stuart.