🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.modula2
Article #393

Type transfer

#393
From: jbaker
Date: Wed, 15 Nov 1989 23:35
34 lines
1577 bytes
I have a question regarding type transfer in Modula-2.
Is it legal to perform type transfer using a type such as this:

TYPE
  String = ARRAY[0.255] OF CHAR;

VAR
  str1 : ARRAY[0..255] OF CHAR;
  str2 : String;

...
  str2 := String(str1);
...

This code sometimes causes a run-time error in my code IF
str1 is not word-aligned. (Apparantly a word level copy is performed.)

Someone at the company which wrote the compiler told me that type transfer
of structures is illegal in Modula-2.  I had never heard this before;
in fact, the reference book I use (Modula-2 Wizard by Richard S. Wiener)
states that the "type identifier of any type may be used to transfer the
                                    ^^^
value of any other type of the same size into that type."
         ^^^

Now, the only way that I can see both the book and the compiler to be correct
(but not the guy I called) is if ARRAY[0..255] OF CHAR is not really a type,
but an array.  Thus the "source type" is really non-existant.  Thus my
compiler would then work since types of size > one byte are word-aligned.

Does anyone else have a book which explains this situation better?

   - John Baker
Technical Details
Message-ID: <2338@gmu90x.gmu.edu>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!uunet!pyrdc!gmu90x!jbaker

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!uunet!pyrdc!gmu90x!jbaker
From: jbaker@gmu90x.gmu.edu (jbaker)
Newsgroups: comp.lang.modula2
Subject: Type transfer
Keywords: type transfer question
Message-ID: <2338@gmu90x.gmu.edu>
Date: 15 Nov 89 23:35:56 GMT
Reply-To: jbaker@gmu90x.UUCP (John Baker)
Organization: George Mason University, Fairfax, Va.
Lines: 34