comp.lang.ada
 help / color / mirror / Atom feed
* Newbie problem: unconstrained subtype not allowed
@ 2005-04-19 22:48 Frank Gerlach
  2005-04-19 23:52 ` Eric Jacoboni
  2005-04-19 23:55 ` Stephen Leake
  0 siblings, 2 replies; 3+ messages in thread
From: Frank Gerlach @ 2005-04-19 22:48 UTC (permalink / raw)


Hello,
I am new to Ada and struggling to get TCP working....
GNAT says "unconstrained subtype not allowed (need initialization)"
when I compile the following piece of code:

   feldEA : Ada.Streams.Stream_Element_Array;

How do I "initialize" this data type ?

Thanks for helping an Ada newbie !



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

* Re: Newbie problem: unconstrained subtype not allowed
  2005-04-19 22:48 Newbie problem: unconstrained subtype not allowed Frank Gerlach
@ 2005-04-19 23:52 ` Eric Jacoboni
  2005-04-19 23:55 ` Stephen Leake
  1 sibling, 0 replies; 3+ messages in thread
From: Eric Jacoboni @ 2005-04-19 23:52 UTC (permalink / raw)


frankgerlach@gmail.com (Frank Gerlach) writes:

>    feldEA : Ada.Streams.Stream_Element_Array;
>
> How do I "initialize" this data type ?
>
> Thanks for helping an Ada newbie !

Type Stream_Element_Array is an unconstrained type:

type Stream_Element_Array is
      array (Stream_Element_Offset range <>) of aliased Stream_Element;

So, you have to constraint it to create a object of this type:

A_Stream_Element_Array : Stream_Element_Array(1..100);

for exemple (a better solution is to use a constrained subtype, but
you've got the idea).

-- 
�ric Jacoboni, n� il y a 1417398423 secondes



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

* Re: Newbie problem: unconstrained subtype not allowed
  2005-04-19 22:48 Newbie problem: unconstrained subtype not allowed Frank Gerlach
  2005-04-19 23:52 ` Eric Jacoboni
@ 2005-04-19 23:55 ` Stephen Leake
  1 sibling, 0 replies; 3+ messages in thread
From: Stephen Leake @ 2005-04-19 23:55 UTC (permalink / raw)
  To: Frank Gerlach; +Cc: comp.lang.ada

frankgerlach@gmail.com (Frank Gerlach) writes:

> Hello,
> I am new to Ada and struggling to get TCP working....

You should probably start with something simpler ...

> 
> GNAT says "unconstrained subtype not allowed (need initialization)"
> when I compile the following piece of code:
>
>    feldEA : Ada.Streams.Stream_Element_Array;
>
> How do I "initialize" this data type ?

This is a mildly confusing message.

Stream_Element_Array is an unconstrained type; it can hold 1 byte, or
20 bytes, whatever you need. 

But, each _object_ of that type must have a definite size. This is the
same as the Ada String type.

So the declaration needs to be something like:

  feldEA : Ada.Streams.Stream_Element_Array (1 .. Max_Buffer_Size);

where Max_Buffer_Size is appropriate for your application.

The "need initialization" is refering to another way for objects of an
unconstrained type to get a definite size; you can provide an initial
value:

   A_String : String := "Hello";

   feldEA : Ada.Streams.Stream_Element_Array := 
     (1 .. Max_Buffer_Size => 0);

In this case, the object size is the same as the initial value size.

-- 
-- Stephe




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

end of thread, other threads:[~2005-04-19 23:55 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-04-19 22:48 Newbie problem: unconstrained subtype not allowed Frank Gerlach
2005-04-19 23:52 ` Eric Jacoboni
2005-04-19 23:55 ` Stephen Leake

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