Page 4 of 4

Re: Oberon Report Update 2016-05-01

Posted: Sat May 21, 2016 11:16 am
by augustk
cfbsoftware wrote:

Code: Select all

MODULE M;

   TYPE
      String = ARRAY 32 OF CHAR;

   VAR
      s: String;
      s1: ARRAY 32 OF CHAR;

PROCEDURE P(s: ARRAY OF CHAR);
BEGIN
  s1 := s
END P;
      
BEGIN
   s := "test";
   P(s)
END M.
Sorry, I missed the fact that the lengths of the arrays in your example are indeed the same. I was more thinking of the following (innocent looking) example:

Code: Select all

MODULE M;

	VAR
		s1: ARRAY 32 OF CHAR;
		
	PROCEDURE P(s: ARRAY OF CHAR);
	BEGIN
		s1 := s
	END P;

BEGIN
	P("test");
END M.
Since the length of the string "test" is less than the length of s1, the assignment may fail and the program is not portable. Correct?

Re: Oberon Report Update 2016-05-01

Posted: Sat May 21, 2016 11:43 am
by cfbsoftware
augustk wrote:Since the length of the string "test" is less than the length of s1, the assignment may fail and the program is not portable. Correct?
No, that should be OK. As the source is an open array the lengths do not have to be the same (that is the new exceptional rule). The result would be the same as the direct assignment:

Code: Select all

s1:= "test";
If the source was larger than the destination it would be an error.

Re: Oberon Report Update 2016-05-01

Posted: Sat May 21, 2016 12:28 pm
by augustk
cfbsoftware wrote:
augustk wrote:Since the length of the string "test" is less than the length of s1, the assignment may fail and the program is not portable. Correct?
No, that should be OK. As the source is an open array the lengths do not have to be the same (that is the new exceptional rule). The result would be the same as the direct assignment:

Code: Select all

s1:= "test";
If the source was larger than the destination it would be an error.
In a previous post in this thread you said "The compiler implementer can decide what the runtime behaviour should be when the lengths are different." In my example the lengths are indeed different; 5 and 32 respectively. Still you say that my example should be fine. That's what I find confusing. I assume you mean "when the source array is longer than the destination array."

Re: Oberon Report Update 2016-05-01

Posted: Sat May 21, 2016 1:40 pm
by cfbsoftware
augustk wrote:I assume you mean "when the source array is longer than the destination array."
Yes - sorry about the confusion.