comp.lang.ada
 help / color / mirror / Atom feed
* Discrimant Record Types and GNAT
@ 1999-01-11  0:00 abailly
  1999-01-12  0:00 ` Samuel Tardieu
  1999-01-12  0:00 ` Matthew Heaney
  0 siblings, 2 replies; 3+ messages in thread
From: abailly @ 1999-01-11  0:00 UTC (permalink / raw)


I've got problems with using discrimant record types with defaults
values
For example :

type Tab is array(POSITIVE range <>) of TOTO;
type REc (taille : NATURAL := 0) is record
    t : tab(1..taille);
end record;

I've been taught by my Ada teacher that this kind of object could be
declared as
tab1 : Rec;
and then used with tab1 := <any_rec>
effectively creating an unconstrained array.

However, when I compile something like that with GNAT (3.10p on a
Linux-i586 box)
I get warnings at compile time and STORAGE_ERROR at runtime, which is
not the case
with another compiler we are using for lessons.

Anyone got an answer to this problem ?

Thank you in advance

Arnaud BAILLY






^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Discrimant Record Types and GNAT
  1999-01-11  0:00 Discrimant Record Types and GNAT abailly
  1999-01-12  0:00 ` Samuel Tardieu
@ 1999-01-12  0:00 ` Matthew Heaney
  1 sibling, 0 replies; 3+ messages in thread
From: Matthew Heaney @ 1999-01-12  0:00 UTC (permalink / raw)


You have use a smaller maximum size.  For example:

  subtype Length_Range is Natural range 0 .. 80;

  type Name_Buffer (Length : Length_Range := 0) is
    record
      Name : String (1 .. Length);
    end record;



abailly <abailly@nordnet.fr> writes:

> I've got problems with using discrimant record types with defaults
> values
> For example :
> 
> type Tab is array(POSITIVE range <>) of TOTO;
> type REc (taille : NATURAL := 0) is record
>     t : tab(1..taille);
> end record;
> 
> I've been taught by my Ada teacher that this kind of object could be
> declared as
> tab1 : Rec;
> and then used with tab1 := <any_rec>
> effectively creating an unconstrained array.
> 
> However, when I compile something like that with GNAT (3.10p on a
> Linux-i586 box)
> I get warnings at compile time and STORAGE_ERROR at runtime, which is
> not the case
> with another compiler we are using for lessons.
> 
> Anyone got an answer to this problem ?
> 
> Thank you in advance
> 
> Arnaud BAILLY




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Discrimant Record Types and GNAT
  1999-01-11  0:00 Discrimant Record Types and GNAT abailly
@ 1999-01-12  0:00 ` Samuel Tardieu
  1999-01-12  0:00 ` Matthew Heaney
  1 sibling, 0 replies; 3+ messages in thread
From: Samuel Tardieu @ 1999-01-12  0:00 UTC (permalink / raw)


>>>>> "Arnaud" == abailly  <abailly@nordnet.fr> writes:

Arnaud> I've been taught by my Ada teacher that this kind of object
Arnaud> could be declared as tab1 : Rec; and then used with tab1 :=
Arnaud> <any_rec> effectively creating an unconstrained array.

Sure, the maximum size will be reserved, that's why you will be able
to store any record in it. However, here the maximum size is the one
of an array with up to Positive'Last components.

Arnaud> Anyone got an answer to this problem ?

There are several solutions of course, two of them being
straightforward:

  - don't set a default value and use pointers
  - use a smaller subtype than positive

  Sam
-- 
Samuel Tardieu -- sam@ada.eu.org




^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~1999-01-12  0:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-01-11  0:00 Discrimant Record Types and GNAT abailly
1999-01-12  0:00 ` Samuel Tardieu
1999-01-12  0:00 ` Matthew Heaney

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