Tuesday January 16, 2007 By working on gcc4/gccfss for OpenSolaris project I found one interesting difference between Studio and GCC compilers.
Studio treats all enumration types in C as signed integers, whereas GCC can put them in unsigned type depending on the values of enumerators.
At first it may look like a minor difference, but in Solaris there was this piece of code:
typedef enum {
A = 0,
B,
C
} en_t;
en_t var;
for (;var >= A; var--);
From GCC point of view the expression "var>=A" is always true, so the loop is collapsed into for(;;) even at -O0 optimization level.
From Studio point of view this code is fine.
Both are correct, because the choice of type is implementation defined by C standard.
This site is a personal blog and is to be used for informational purposes only. The views expressed on this blog are those of the author only, and should not be attributed to any past or present employers.