Login | Register
My pages Projects Community openCollabNet

Discussions > users > Element and No_Element

charles
Discussion topic

Back to topic list

Element and No_Element

Reply

Author Georg Bauhaus <bauhaus at arcor dot de>
Full name Georg Bauhaus <bauhaus at arcor dot de>
Date 2005-10-15 12:31:46 PDT
Message Consider

with Ada.Containers.Vectors;

procedure Crsr3 is

   package Int_Vecs is new Ada.Containers.Vectors
     (Element_Type => Integer,
      Index_Type => Positive);

   use Int_Vecs;

   e: Integer;

begin -- Crsr3

   e := Element(No_Element);

end Crsr3;


When Element is called with No_Element (or some Cursor that
has run into No_Element), then according to the RM, there should
be a Constraint_Error, IINM. Instead there is a

 STORAGE_ERROR : stack overflow (or erroneous memory access)

(130/2 {AI95-00302-03} If Position equals No_Element,
 then Constraint_Error is propagated.)

I believe this is caused by No_Element.Container = null when
the Cursor based Element function calls the indexed
based Element function with a null pointer for Container:

   return Element (Position.Container.all, Position.Index);
        where Position = No_Element = Cursor'(null, ...)!

and the index based Element function uses

   return Container.Elements (T'(Index));


Incidentally, the above situation has come up in a discussion
of "bounds checking loops" vs. having the iteration run into
an exception. The latter turns out to be potentially faster in
some languages/implementations, including GNAT. Like in

   --while Has_Element(k)
   loop
      op(k);
      Next(k);
   end loop;

« Previous message in topic | 1 of 4 | Next message in topic »

Messages

Show all messages in topic

Element and No_Element Georg Bauhaus <bauhaus at arcor dot de> Georg Bauhaus <bauhaus at arcor dot de> 2005-10-15 12:31:46 PDT
     Re: Element and No_Element Matthew Heaney <mheaney at on2 dot com> Matthew Heaney <mheaney at on2 dot com> 2005-10-17 07:41:52 PDT
         Re: Element and No_Element Georg Bauhaus <bauhaus at arcor dot de> Georg Bauhaus <bauhaus at arcor dot de> 2005-10-17 11:43:19 PDT
             Re: Element and No_Element Matthew Heaney <mheaney at on2 dot com> Matthew Heaney <mheaney at on2 dot com> 2005-10-17 11:55:31 PDT
Messages per page: