comp.lang.ada
 help / color / mirror / Atom feed
From: Ken Garlington <kennieg@nospam.flash.net>
Subject: Re: Beware: Rep spec on an enumeration type clause
Date: 1997/12/12
Date: 1997-12-12T00:00:00+00:00	[thread overview]
Message-ID: <3491E444.679E@nospam.flash.net> (raw)
In-Reply-To: 34912418.13716044@news.geccs.gecm.com


Brian Orpin wrote:

> In 83 I would have simply checked to see if it was valid by
> 
> Valid := I in T'First .. T'Last;
> 
> Certainly on the Tartan Compiler for C40 this detects any invalid (not
> represented) values of T.

Be careful with this! Consider the following example (not compiled, so
forgive any minor errors):

  type IO_Value is range 0 .. 15;
  for IO_Value'Size use 16;

  Raw_Value : IO_Value;

  Raw_IO.Read ( Raw_Value );
  if Raw_Value not in IO_Value'Range then
    <handle error>
  else
    ...
  end if;

If Raw_IO.Read returns a value out of range 0 .. 15, the check is
NOT GUARANTEED TO WORK. In particular, the TI/Tartan compiler for
the MIL-STD-1750 (among others) will delete the check under almost
all optimization levels (a fact I learned from painful personal
experience), since Raw_Value is "known" to be in the range of its
type upon return from the Read call.

This is at least one of the reasons why 'Valid was introduced in
the first place.

> 
> --
> Brian Orpin    (These thoughts are my own ......... for once!)
> brian.orpin@gecm(dot)com or BrianOrpin@Bigfoot.com
> http://www.borpin.demon.co.uk/  **Anti-spam reply-to**




      parent reply	other threads:[~1997-12-12  0:00 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1997-12-12  0:00 Beware: Rep spec on an enumeration type clause Franco Mazzanti
1997-12-12  0:00 ` Ken Garlington
     [not found] ` <34912418.13716044@news.geccs.gecm.com>
1997-12-12  0:00   ` Matthew Heaney
     [not found]     ` <349e19ec.16536708@news.geccs.gecm.com>
1997-12-18  0:00       ` Matthew Heaney
     [not found]         ` <349a4134.5569381@news.geccs.gecm.com>
1997-12-19  0:00           ` Matthew Heaney
1997-12-12  0:00   ` Ken Garlington [this message]
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox