comp.lang.ada
 help / color / mirror / Atom feed
* unconstrainted arrays
@ 2001-10-17 15:18 Alfred Hilscher
  2001-10-17 15:35 ` Lutz Donnerhacke
  2001-10-17 16:09 ` unconstrainted arrays Claude SIMON
  0 siblings, 2 replies; 12+ messages in thread
From: Alfred Hilscher @ 2001-10-17 15:18 UTC (permalink / raw)


Hi,

I know that I can define unconstrainted array where the actual
constraints are given later:

type My_Array is array (<>) of Integer;

A1 : My_Array (1..10);



Moreover I know a way to use this with structure:

type s (len : integer) is record
            X,Y : Integer;
            A : My_Array (1..Len);
     end record;

PTs : s (10);


But this would add one extra component to the record (Len). Is there a
way to avoid this extra component ? Maybe a pragma or rep-specs ? Its
encapsulated within a package body for HW handling where the extra
component is unwanted.

Thanks.



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

* Re: unconstrainted arrays
  2001-10-17 15:18 unconstrainted arrays Alfred Hilscher
@ 2001-10-17 15:35 ` Lutz Donnerhacke
  2001-10-17 16:28   ` Alfred Hilscher
  2001-10-17 16:09 ` unconstrainted arrays Claude SIMON
  1 sibling, 1 reply; 12+ messages in thread
From: Lutz Donnerhacke @ 2001-10-17 15:35 UTC (permalink / raw)


* Alfred Hilscher wrote:
>type s (len : integer) is record
>            X,Y : Integer;
>            A : My_Array (1..Len);
>     end record;
>
>PTs : s (10);
>
>But this would add one extra component to the record (Len). Is there a
>way to avoid this extra component ? Maybe a pragma or rep-specs? Its
>encapsulated within a package body for HW handling where the extra
>component is unwanted.

type hw_s10 is record
    X,Y : Integer;
    A : My_Array (1..10);
end record;
for hw_s10 use record
   x at 0 range 0 .. 15;
   y at 2 range 0 .. 15;
   a at 4 range 0 .. 159;
end record;

If you are requireing a special layout, describe it directly. If the
discriminant occurs in the record at an other place: No problem:

type pascal_len is range 0 .. 255;
type pascal_string (len : pascal_len) is record
   value : String (1 .. len);
end record;
for pascal_string use record
   len at 0 range 0 .. 7;
end record;
pragma Pack (pascal_string);




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

* Re: unconstrainted arrays
  2001-10-17 15:18 unconstrainted arrays Alfred Hilscher
  2001-10-17 15:35 ` Lutz Donnerhacke
@ 2001-10-17 16:09 ` Claude SIMON
  1 sibling, 0 replies; 12+ messages in thread
From: Claude SIMON @ 2001-10-17 16:09 UTC (permalink / raw)




Alfred Hilscher a �crit :

> Hi,
>
> I know that I can define unconstrainted array where the actual
> constraints are given later:
>
> type My_Array is array (<>) of Integer;
>
> A1 : My_Array (1..10);
>
> Moreover I know a way to use this with structure:
>
> type s (len : integer) is record
>             X,Y : Integer;
>             A : My_Array (1..Len);
>      end record;
>
> PTs : s (10);
>
> But this would add one extra component to the record (Len). Is there a
> way to avoid this extra component ? Maybe a pragma or rep-specs ? Its
> encapsulated within a package body for HW handling where the extra
> component is unwanted.

One way is :

generic
   type Indices is range <>;
package Structure is
   type My_Array is array (Indices) of Integer;
   type S is record
            X,Y : Integer;
            A : My_Array;
     end record;
end Structure;


Claude Simon




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

* Re: unconstrainted arrays
  2001-10-17 15:35 ` Lutz Donnerhacke
@ 2001-10-17 16:28   ` Alfred Hilscher
  2001-10-18  7:42     ` Lutz Donnerhacke
  0 siblings, 1 reply; 12+ messages in thread
From: Alfred Hilscher @ 2001-10-17 16:28 UTC (permalink / raw)


Sorry, the description of my problem was bad. I try to make it clearer.

My current problem is to define the record in such a way, that I can
declare different variables like

PTs_1 : s(10);
PTs_2 : s(16);
PTs_3 : s(24);
PTs_4 : s(58);

whereby the data must be always stored in the order X, Y, A(1), A(2) ..
A(n). A trailing discriminant would be no problem, but nevertheeless
should be avoided (if possible). The component "Len" is not really
needed (I think I could obtain the length of "A" by A'Length, but I do
not need it).


 Lutz Donnerhacke wrote:
 >  
 > * Alfred Hilscher wrote:
 > >type s (len : integer) is record
 > >            X,Y : Integer;
 > >            A : My_Array (1..Len);
 > >     end record;
 > >
 > >PTs : s (10);
 > >
 > >But this would add one extra component to the record (Len). Is there
a
 > >way to avoid this extra component ? Maybe a pragma or rep-specs? Its
 > >encapsulated within a package body for HW handling where the extra
 > >component is unwanted.
 > 
 > type hw_s10 is record
 >     X,Y : Integer;
 >     A : My_Array (1..10);
 > end record;
 > for hw_s10 use record
 >    x at 0 range 0 .. 15;
 >    y at 2 range 0 .. 15;
 >    a at 4 range 0 .. 159;
 > end record;
 > 
 > If you are requireing a special layout, describe it directly. If the
 > discriminant occurs in the record at an other place: No problem:
 > 
 > type pascal_len is range 0 .. 255;
 > type pascal_string (len : pascal_len) is record
 >    value : String (1 .. len);
 > end record;
 > for pascal_string use record
 >    len at 0 range 0 .. 7;
 > end record;
 > pragma Pack (pascal_string);



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

* Re: unconstrainted arrays
  2001-10-17 16:28   ` Alfred Hilscher
@ 2001-10-18  7:42     ` Lutz Donnerhacke
  2001-10-18 11:03       ` Rep spec still not possible Petter Fryklund
  0 siblings, 1 reply; 12+ messages in thread
From: Lutz Donnerhacke @ 2001-10-18  7:42 UTC (permalink / raw)


* Alfred Hilscher wrote:
>My current problem is to define the record in such a way, that I can
>declare different variables like
>
>PTs_1 : s(10);
>PTs_2 : s(16);
>PTs_3 : s(24);
>PTs_4 : s(58);
>
>whereby the data must be always stored in the order X, Y, A(1), A(2) ..
>A(n). A trailing discriminant would be no problem, ...

Ada record representation clauses can't do this. But Claude's suggestion of
a generic package should solve your problem.



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

* Rep spec still not possible.
  2001-10-18  7:42     ` Lutz Donnerhacke
@ 2001-10-18 11:03       ` Petter Fryklund
  2001-10-18 12:44         ` Lutz Donnerhacke
  0 siblings, 1 reply; 12+ messages in thread
From: Petter Fryklund @ 2001-10-18 11:03 UTC (permalink / raw)


   generic
      type Indices is range <>;
   package Structure is
      type My_Array is array (Indices) of Integer;

      type S is record
         X,Y : Integer;
         A : My_Array;
      end record;

      My_Array_Length : constant Integer :=
        Integer ((Indices'Last - Indices'First + 1) * 8);

      for S use record
         X at 0 range 0 .. 31;
         Y at 4 range 0 .. 31;
         A at 8 range 0 .. My_Array_Length - 1; <--- Expression not static.
      end record;

   end Structure;

I've been in this alley before but I didn't find may way around, does
anybody have any suggestions?






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

* Re: Rep spec still not possible.
  2001-10-18 11:03       ` Rep spec still not possible Petter Fryklund
@ 2001-10-18 12:44         ` Lutz Donnerhacke
  2001-10-18 17:10           ` Jeffrey Carter
  0 siblings, 1 reply; 12+ messages in thread
From: Lutz Donnerhacke @ 2001-10-18 12:44 UTC (permalink / raw)


* Petter Fryklund wrote:
>   generic
>      type Indices is range <>;
>   package Structure is
>      type My_Array is array (Indices) of Integer;
>
>      type S is record
>         X,Y : Integer;
>         A : My_Array;
>      end record;
>
>      My_Array_Length : constant Integer :=
>        Integer ((Indices'Last - Indices'First + 1) * 8);
>
>      for S use record
>         X at 0 range 0 .. 31;
>         Y at 4 range 0 .. 31;
>         A at 8 range 0 .. My_Array_Length - 1; <--- Expression not static.

Comment it out. Works.

>      end record;

Use pragma Pack. As posted in this thread some articles ago.

>   end Structure;




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

* Re: Rep spec still not possible.
  2001-10-18 12:44         ` Lutz Donnerhacke
@ 2001-10-18 17:10           ` Jeffrey Carter
  2001-10-19 13:52             ` Exactly the prblem, how do we make a known constant value static? Petter Fryklund
  0 siblings, 1 reply; 12+ messages in thread
From: Jeffrey Carter @ 2001-10-18 17:10 UTC (permalink / raw)


Lutz Donnerhacke wrote:
> 
> * Petter Fryklund wrote:
> >   generic
> >      type Indices is range <>;
> >   package Structure is
> >      type My_Array is array (Indices) of Integer;
> >
> >      My_Array_Length : constant Integer :=
> >        Integer ((Indices'Last - Indices'First + 1) * 8);


This seems wrong. What you want is probably My_Array'Size. Since it's
not static, the value is useless for a rep clause anyway.

-- 
Jeffrey Carter



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

* Exactly the prblem, how do we make a known constant value static?
  2001-10-18 17:10           ` Jeffrey Carter
@ 2001-10-19 13:52             ` Petter Fryklund
  2001-10-20  0:04               ` James Rogers
  2001-10-20  2:53               ` Jeffrey Carter
  0 siblings, 2 replies; 12+ messages in thread
From: Petter Fryklund @ 2001-10-19 13:52 UTC (permalink / raw)


Sure, my mistake. It would have been correct if we had been working on
bytes, but still, how do we make a rep spec?

My_Array_Length : constant Integer :=  Integer ((Indices'Last -
Indices'First + 1) * 4 * 8);

I'm not sure what Lutz meant by comment it out, it works, above. Wouldn't
that depend on the implementation?


Jeffrey Carter wrote in message <3BCF0D06.DD1D45F6@boeing.com>...
>Lutz Donnerhacke wrote:
>>
>> * Petter Fryklund wrote:
>> >   generic
>> >      type Indices is range <>;
>> >   package Structure is
>> >      type My_Array is array (Indices) of Integer;
>> >
>> >      My_Array_Length : constant Integer :=
>> >        Integer ((Indices'Last - Indices'First + 1) * 8);
>
>
>This seems wrong. What you want is probably My_Array'Size. Since it's
>not static, the value is useless for a rep clause anyway.
>
>--
>Jeffrey Carter





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

* Re: Exactly the prblem, how do we make a known constant value static?
  2001-10-19 13:52             ` Exactly the prblem, how do we make a known constant value static? Petter Fryklund
@ 2001-10-20  0:04               ` James Rogers
  2001-10-20  2:53               ` Jeffrey Carter
  1 sibling, 0 replies; 12+ messages in thread
From: James Rogers @ 2001-10-20  0:04 UTC (permalink / raw)


Petter Fryklund wrote:
> 
> Sure, my mistake. It would have been correct if we had been working on
> bytes, but still, how do we make a rep spec?
> 
> My_Array_Length : constant Integer :=  Integer ((Indices'Last -
> Indices'First + 1) * 4 * 8);
> 
> I'm not sure what Lutz meant by comment it out, it works, above. Wouldn't
> that depend on the implementation?

Lutz was saying to comment out the rep spec and simply pack the
array. That would work.

As far a portability, your solution is the one which depends upon
implementation. You are assuming that an Integer is 32 bits.
Using My_Array_Length := My_Array'Size is always poratable and
correct.

Remember that the Size attribute reports the number of BITS used
for a type or object, unlike the "sizeof" operator in C and C++
that reports the number of "bytes" with the definition of "bytes"
being implementation dependent.

Jim Rogers
Colorado Springs, Colorado USA



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

* Re: Exactly the prblem, how do we make a known constant value static?
  2001-10-19 13:52             ` Exactly the prblem, how do we make a known constant value static? Petter Fryklund
  2001-10-20  0:04               ` James Rogers
@ 2001-10-20  2:53               ` Jeffrey Carter
  2001-10-22  8:11                 ` We still don't know how to make a " Petter Fryklund
  1 sibling, 1 reply; 12+ messages in thread
From: Jeffrey Carter @ 2001-10-20  2:53 UTC (permalink / raw)


Petter Fryklund wrote:
> 
> Sure, my mistake. It would have been correct if we had been working on
> bytes, but still, how do we make a rep spec?

Since the array's size depends on a generic parameter, there is no way
to obtain a static size for the array to use in a rep spec. The only way
is to specify the components that come before the array, pack the
record, and hope the compiler positions everything where you need it.

> 
> My_Array_Length : constant Integer :=  Integer ((Indices'Last -
> Indices'First + 1) * 4 * 8);

If Integer'Size is 32, this is the same as My_Array'Size.

-- 
Jeff Carter
"English bed-wetting types."
Monty Python & the Holy Grail



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

* We still don't know how to make a value static?
  2001-10-20  2:53               ` Jeffrey Carter
@ 2001-10-22  8:11                 ` Petter Fryklund
  0 siblings, 0 replies; 12+ messages in thread
From: Petter Fryklund @ 2001-10-22  8:11 UTC (permalink / raw)


Wouldn't it be nice if we could make a proper rep spec of the record? Of
course, I should have specified Integer to be 32 bits, but that's beside the
point.





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

end of thread, other threads:[~2001-10-22  8:11 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-10-17 15:18 unconstrainted arrays Alfred Hilscher
2001-10-17 15:35 ` Lutz Donnerhacke
2001-10-17 16:28   ` Alfred Hilscher
2001-10-18  7:42     ` Lutz Donnerhacke
2001-10-18 11:03       ` Rep spec still not possible Petter Fryklund
2001-10-18 12:44         ` Lutz Donnerhacke
2001-10-18 17:10           ` Jeffrey Carter
2001-10-19 13:52             ` Exactly the prblem, how do we make a known constant value static? Petter Fryklund
2001-10-20  0:04               ` James Rogers
2001-10-20  2:53               ` Jeffrey Carter
2001-10-22  8:11                 ` We still don't know how to make a " Petter Fryklund
2001-10-17 16:09 ` unconstrainted arrays Claude SIMON

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