compiler thoughts

All | Personal | Sun
« Ultra3 vs Ultra4 | Main | interesting bug »
20070116 Tuesday January 16, 2007

enumerations

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.

Posted by alexey ( Jan 16 2007, 06:39:18 PM PST ) Permalink

Comments:

Post a Comment:

Comments are closed for this entry.

Disclaimer:

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.

Calendar

RSS Feeds

Search

Links

Navigation

Referers