southwesthustla <fdkelly@[EMAIL PROTECTED]
> wrote:
>
> >
> > I think you should write what you really want to do. If you want
> > copy content of a set to an array of 16-bit integers (or back) you
> > can use Move builtin routine.
>
> That's exactly what I want to do. The move command seems to work and
> so I have managed to create an array of 16-bit integers sized at 14-
> bytes total. The problem still arises however, when I try to cast/
> write this array onto a 112-element set. Firstly due to the set being
> worth 16 bytes in 32-bit gpc. Secondly as the two items are not the
> same 'shape' in memory I get a crash on execution.
>
> I have tried re-sizing the array of 16 bit integers to have an extra
> 'blank' row, to bring its size up to 16 bytes. This removes the 'cast
> to type of different size' warning. However still crashes with
> segmentation errors on running, perhaps due to memory "beyond
> allocated size" as you say.
>
If you have variables of the same size cast should work OK:
{ To compile: gpc -fautomake cass.pas }
program cass;
uses gpc;
type at = array [0..7] of ShortInt;
st = set of 0..111;
var a : at;
b : st;
i : integer;
begin
b := [13, 17];
a := at(b);
for i := 0 to 7 do
write(a[i], ', ');
writeln;
a[2] := 15;
b := st(a);
write('[');
for i := 0 to 111 do
if i in b then write(i, ', ');
writeln(']');
end
..
If your program crashes, post a _complete_ compilable program that
crashes, command line used and the output of gpc -v. Try to
simplify cra****ng part: it is quite likely that in the process
you will notice error in your program.
> Generally, what determines the size/shape of memory allocated for a
> set or an array?
>
ATM all gpc variables have simple shape: they are allocated in a
sequence of consequitive memory locations. There may be padding
between components, but this padding is considered part of the
variable.
For sets gpc allocate a sequence of machine words big enough to
hold the set. If lower bound is an integer not divisible by
the word size gpc adds extra padding at the begining. Note
that gpc idea of word size may be different than yours (IIRC
on m68k gpc uses 32-bit words).
In the future gpc probably will optimize space used by small
sets and allocate them in half-word or byte if possible.
Plain (non-schema) arrays just are a sequence of elements.
> Concerning crash: accessing memory
> > beyond allocated size is likely to cause crash (in newer gpc versions
> > most such cases should be caught by range checking).
>
> Do you happen to know which 'newer' gpc version will work smoothly in
> conjunction with gcc?
>
All versions should work well with matching gcc version. The newest is
gpc-20060325. Full range checking appeared in gpc-20050217, but the
first version had some problems, so you probably want later one.
--
Waldek Hebisch
hebisch@[EMAIL PROTECTED]


|