This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Ada subtypes and base types


On Thu, 2006-03-23 at 10:40 +0100, Duncan Sands wrote:
> Hi Jeff, this seems to work nicely - thanks again.  I still see a bunch
> of suboptimal range calculations in the Ada code I'm looking at, but these
> now just coming from having everything initialised to VR_VARYING rather than
> [TYPE_MIN, TYPE_MAX].  Do you know of any way of getting variables with
> non-trivial TYPE_MIN/TYPE_MAX values in C?  I ask because I'd rather produce
> test cases in C than Ada, since everyone has access to a C compiler :)
You can't -- min/max will be extended to cover the type's precision,
even for enumerated types. 

enum x
{
  RED == 0,
  GREEN = 1,
  BLUE = 2,
  PURPLE = 3,
}

for (color = RED, color <= PURPLE; color++)
{
   ...
}

Note carefully that for the loop test to terminate that color
will have the value PURPLE+1 (4).  If the type min/max were set to
0, 3 respectively then the loop exit test would be optimized away...

Jeff


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]