gm2
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Gm2] Use of functions in expressions


From: Scott Robinson
Subject: [Gm2] Use of functions in expressions
Date: Sat, 15 Nov 2008 12:45:29 -0600

Hi all,

I have another Modula-2 language question about function results and using them in expressions. Specifically, it seems that the language allows you to return an array or a pointer but apparently (at least according to the GM2 compiler) does not allow you to turn around and use an array subscript to access a particular element of the array within an expression. The pointer dereference operator '^' also appears to be illegal after a call to a function.

A specific example:

MODULE test1;

FROM InOut IMPORT WriteString, Write, WriteLn;

TYPE
 tArr = ARRAY [0..9] OF CHAR;

VAR
 temp : tArr;

PROCEDURE tester() : tArr;
BEGIN
 RETURN "testing";
END tester;

BEGIN

 (* This works *)
 WriteString("The 5th character returned is ");
 temp := tester();
 Write(temp[4]);
 WriteLn;

 (* This does not work *)
 WriteString("The 5th character returned is ");
 Write(tester()[4]);
 WriteLn;

END test1.

GM2 gives the following for the above:

# gm2 -c test1.mod
test1.mod:26:3: error: syntax error, found `['
test1.mod:30:1: error: compilation failed

I'm wondering if the Modula-2 ISO standard specifically disallows that syntax? And, if anyone has access to other Modula-2 compilers, do those compilers accept the above?

Thanks,
Scott





reply via email to

[Prev in Thread] Current Thread [Next in Thread]