comp.lang.ada
 help / color / mirror / Atom feed
From: AdaMagica <christoph.grein@eurocopter.com>
Subject: Re: getting back to null range
Date: Sun, 12 Jul 2009 11:20:07 -0700 (PDT)
Date: 2009-07-12T11:20:07-07:00	[thread overview]
Message-ID: <a02606b2-1b81-432f-9ee4-4bbd09c69f2a@k26g2000vbp.googlegroups.com> (raw)
In-Reply-To: HNu5m.431349$4m1.352067@bgtnsc05-news.ops.worldnet.att.net

This is an excerpt (and slightly modified) of what anon proposed as a
test program.
----
with Ada.Integer_Text_IO ;
with Ada.Text_IO ;

use Ada.Integer_Text_IO ;
use Ada.Text_IO ;

procedure t is

  -- Display String values, with a title

  procedure Put ( T : String ; B : String ) is

    begin
      Put ( T ) ;
      Put ( "'( " ) ;
      Put ( B'First ) ;
      Put ( " .. " ) ;
      Put ( B'Last ) ;
      Put ( " ) => " ) ;
      Put ( B ) ;
      Put ( ", Length => " ) ;
      Put ( B'length ) ;
      New_Line;
    end Put ;

  A : Positive range -5 .. -7 ; -- Value is a nul range
                                -- Creates the compiler warning
message

begin

  declare
    --  Without these pragma statements the following declaration
    --  statement will compile but generates an C_E at run time
--      pragma Suppress ( Index_Check ) ;
--      pragma Suppress ( Range_Check ) ;

    S_B : String := ( A => 'Z' ) ; -- should be equal to S_A

  begin
    Put (A);  Put (A'Size);  New_Line;
    Put ( "null S_B", S_B ) ;
  end ;

end t ;
---
I do not understand what (s)he want's to prove with this piece of
code.

The declaration of A produces a warning, because it is read but never
assigned. His (her) assertion that the value is a null range is wrong.
A value is *never* a range. The subtype of A is a null range so that
one cannot assign any value to A. But nevertheless A exists and has a
size and an address and there is some random sequence of bits at that
address which can be interpreted as an integer.

My result is:
    4201563         32
null S_B'(     4201563 ..     4201563 ) => Z, Length =>           1

anon got an exception without pragma Suppress because in his case A
had the sequence of bit that interpreted as integer was 0, which is
not in range of Positive. So the exception is appropriate. If (s)he
suppresses the check, the program is erroneous if the check would have
failed. So what does (s)he prove with an erroneous program?

In my case, the value is in Positive, so no exception.

And of course S_B is not a null string because it is initialized with
an aggregate that has a value (albeit a random one).

For any integers A, B such that the following is legal

  X: String := (A..B => something);  -- A..B is a range (might be a
null range)

is not the same as

  X: String := (A => something);  -- an aggregate with one component
(if A in Positive)



      reply	other threads:[~2009-07-12 18:20 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-07-09 23:10 getting back to null range anon
2009-07-12 18:20 ` AdaMagica [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