[M3devel] open vs. fixed arrays?

Tony Hosking hosking at cs.purdue.edu
Tue May 13 17:28:24 CEST 2008


On May 13, 2008, at 9:52 AM, Jay wrote:

> I'm being a bit lazy here. I could experiment more with the compiler  
> and check the green book.
>
>
> The compiler does not correctly implement:
>
>
>
>  VAR a : ARRAY [0..0] OF CHAR := ARRAY OF CHAR {'a'};
>
> at least for reasons of alignment.
>
>
> What is this code supposed to mean?
It should assign the elements of the open array to those of the fixed  
array.
>
>
>
> Is ARRAY OF CHAR {'a'} a constant fixed array with a deduced size of  
> 1?

No, it is open.

>
> Or a constant open array with a deduced size of 1?
No.
> I believe it is supposed to be a constant open array.
Yes.

>
>
> And then, what is the difference?
> What are the visible differences?
>
>
> Between
>
>  VAR a : ARRAY [0..0] OF CHAR := ARRAY OF CHAR {'a'};
> and
>   VAR a : ARRAY [0..0] OF CHAR := ARRAY [0..0] OF CHAR {'a'};
>
> Can I act on "a" different at runtime between the two?
> Given that its static type is the same, I doubt it. But I haven't  
> really thought about it.
>
>
> If there is no visible difference, should the compiler implement it  
> as the second -- probably saving a tiny bit of space.
>
>
> And if not, is it supposed to generate an open array, and an  
> initializer to do the copy?
Probably should.

>
>
>
> A constant like
> CONST a = ARRAY OF CHAR{'a'}
>
>
> is an open array I believe, with visible differences, I think, not  
> sure,
> so in the unlikely even that a "bigger" change is ok here, it has to  
> be careful of this and other scenarios.
>
>
> Really, I'm just being a bit slow. I bet these should remain open  
> arrays but somewhere the compiler gets confused and computes the  
> alignment and perhaps size as a fixed array, leading to assertion  
> failures in the compiler, depending on the actual sizes, e.g.:
>
>
> MODULE Main;
> <*UNUSED*> VAR a : ARRAY [0..0] OF CHAR := ARRAY OF CHAR {'a'};
> <*UNUSED*> VAR b : ARRAY OF CHAR := ARRAY OF CHAR {'a'};
> BEGIN
> END.
>
>
> fails an assertion in the compiler, depending on the target -- but I  
> expect all x86/AMD64 targets.
>
> Thanks,
>  - Jay

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://m3lists.elegosoft.com/pipermail/m3devel/attachments/20080513/02b6d13d/attachment-0002.html>


More information about the M3devel mailing list