Oberon Report Update 2016-05-01

Topics related to the use of Oberon language features
augustk
Posts: 54
Joined: Mon Sep 05, 2011 5:21 pm
Location: Sweden

Re: Oberon Report Update 2016-05-01

Post by augustk » Sat May 21, 2016 11:16 am

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?

cfbsoftware
Site Admin
Posts: 525
Joined: Fri Dec 31, 2010 12:30 pm
Contact:

Re: Oberon Report Update 2016-05-01

Post by cfbsoftware » Sat May 21, 2016 11:43 am

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.

augustk
Posts: 54
Joined: Mon Sep 05, 2011 5:21 pm
Location: Sweden

Re: Oberon Report Update 2016-05-01

Post by augustk » Sat May 21, 2016 12:28 pm

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."

cfbsoftware
Site Admin
Posts: 525
Joined: Fri Dec 31, 2010 12:30 pm
Contact:

Re: Oberon Report Update 2016-05-01

Post by cfbsoftware » Sat May 21, 2016 1:40 pm

augustk wrote:I assume you mean "when the source array is longer than the destination array."
Yes - sorry about the confusion.

Post Reply