[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Gm2] CAST Woes
From: |
Gaius Mulley |
Subject: |
Re: [Gm2] CAST Woes |
Date: |
20 Jun 2005 16:58:59 +0100 |
User-agent: |
Gnus/5.09 (Gnus v5.9.0) Emacs/21.4 |
john o goyo <address@hidden> writes:
> Iztok:
>
> Thank you for your comment. I shall first report my findings and
> then explain what I was trying to do.
>
> Izo wrote:
> > john o goyo wrote:
> >
> >>
> >>
> >> ------------------------------------------------------------
> >> 2. CASTing woes:
> >>
> >> Is the following not valid?
> >>
> >> ===[cast.mod]===
> >> MODULE cast;
> >>
> >> FROM (*ISO*) SYSTEM IMPORT CAST, LOC;
> >>
> >> VAR
> >> x :LOC;
> >> n :CARDINAL;
> >>
> >> BEGIN (*cast*)
> >> n := 2;
> >> x := CAST(LOC, n) (* Reported as error by GM2 of 2005-06-03 *)
> >> END cast.
> >> ===[cast.mod ends]===
> >>
> >> ------------------------------------------------------------
> >>
> > John, have you checked the LOC with the ISO M2 standard ? I think
> > that I remember (still, I might be badly wrong ...) that the LOC has
> > some restrictions at being used as container. I think that the LOC
> > was meant to be special and used only as the input (especcially as
> > the open array) parameter in procedure definitions since it could be
> > interpreted afterwards in the procedure implementation as any given
> > type. If I am correct, already the "x : LOC" line is incorrect and
> > not only "x := CAST(LOC, n);"
> > I think that you (and Gaius) should really check this with the
> > standard.
Hi,
from my reading of the standard p.352 says, "
NOTES
1 The only operation directly defined on the location type is
assignment.
2 There are special rules affecting parameter compatibility for
system storage types, the corresponding actual parameter may be
of any type that is represented in a corresponding number of
storage locations - see section 6.9.3.3.
"
which talks about ARRAY OF LOC and not passing constants to this
(amoungst many other issues).
My interpretation from (1) above is that:
x := CAST(LOC, n)
should be legal. At least the section on CAST does not forbid using
LOC as the type parameter.
> ================================================================
> 2. Why LOC?
>
> I was trying to compile some code that marshalled CARDINAL values
> into bytes for storage and transport. I cannot use CHAR to hold
> them because the standard makes no assertion on the size of CHARs.
> Other compilers accept BYTE and some even allowed something such
> as "byte := cardinal MOD 256".
BYTE is also available in ISO and PIM but no guarantee is made in
ISO that TSIZE(BYTE)=1, whereas TSIZE(LOC) will always be 1.
Using LOC appears more portable.
Gaius