Discussion:
LEN and pointers
(too old to reply)
akarl
2005-06-25 16:15:54 UTC
Permalink
Hi all,

Does anyone know why the built in function LEN does not accept pointers
to arrays when `.' and `[]' implies pointer dereference? (E.g. `LEN(s)'
is not valid if `s: POINTER TO ARRAY OF CHAR'.)
Chris Burrows
2005-06-26 10:56:44 UTC
Permalink
Does anyone know why the built in function LEN does not accept pointers to
arrays when `.' and `[]' implies pointer dereference? (E.g. `LEN(s)' is
not valid if `s: POINTER TO ARRAY OF CHAR'.)
It works OK for me using the ETH PlugIn Oberon for Windows. Which flavour of
Oberon are you using?

--
Chris Burrows
CFB Software
http://www.cfbsoftware.com/gpcp
akarl
2005-06-26 16:14:35 UTC
Permalink
Post by Chris Burrows
Does anyone know why the built in function LEN does not accept pointers to
arrays when `.' and `[]' implies pointer dereference? (E.g. `LEN(s)' is
not valid if `s: POINTER TO ARRAY OF CHAR'.)
It works OK for me using the ETH PlugIn Oberon for Windows. Which flavour of
Oberon are you using?
Interesting. I use OOC and XDS. According to the Oberon report the
argument type of LEN must be an array.

[src]$ cat Test.ob2
MODULE Test;
IMPORT Out;
VAR s: POINTER TO ARRAY OF CHAR;
BEGIN
NEW(s, 10);
Out.Int(LEN(s), 0); Out.Ln
END Test.

[src]$ xc =m Test.ob2 +MAIN +CHANGESYM
O2/M2 development system v2.51 (c) 1999-2003 Excelsior, LLC. (build
10.05.2005)
XDS Oberon-2 v2.40 [x86, v1.50] - build 10.05.2005
Compiling "Test.ob2"

* [Test.ob2 6.16 E050]
* object is not array
Out.Int(LEN($s), 0); Out.Ln
errors 1, no warnings, lines 16, time 0.01
Chris Burrows
2005-06-27 04:13:30 UTC
Permalink
Post by akarl
Post by Chris Burrows
Post by akarl
Does anyone know why the built in function LEN does not accept pointers
to arrays when `.' and `[]' implies pointer dereference? (E.g. `LEN(s)'
is not valid if `s: POINTER TO ARRAY OF CHAR'.)
It works OK for me using the ETH PlugIn Oberon for Windows. Which flavour
of Oberon are you using?
Interesting. I use OOC and XDS. According to the Oberon report the
argument type of LEN must be an array.
Yes - you are right. However, it looks as if others have been concerned
about this issue as the Component Pascal language report (which was derived
from the Oberon report) adds the following:

'Dereferencing is also implied if a pointer is assigned to a variable of a
record or array type (Ch. 9.1), if a pointer is used as actual parameter for
a formal parameter of a record or array type (Ch. 10.1), or if a pointer is
used as argument of the standard procedure LEN (Ch. 10.3).'

http://www.oberon.ch/pdf/CP-Lang.pdf

I guess that to be safe you should explicitly dereference the array, i.e.
use the construct:

LEN(s^)

This should always work whichever version of Oberon or Component Pascal you
are using.

--
Chris Burrows
CFB Software
http://www.cfbsoftware.com/gpcp

Continue reading on narkive:
Loading...