- Length of string varies!

From: [at]} <Gérard>
Date: Fri, 29 Sep 2006 20:23:47 +0200

----boundary-LibPST-iamunique-1716130496_-_-
Content-type: text/plain

Douglas G. Danforth a écrit :
>
>
> Gérard Meunier wrote:
>> Douglas G. Danforth a écrit :
>>> Folks,
>>> I just discovered that the length of a string varies depending
>>> upon whether it is used directly or passed as an argument to
>>> a procedure for example
>>>
>>> VAR x: ARRAY 32 OF CHAR;
>>> x := "HI";
>>>
>>> will have length
>>> LEN(x$) = 2
>>> but will have length
>>> LEN(y) = 3
>>> when it is passed to a procedure with argument y.
> ...
>> It's because you pass x$, and not x itself. x$ is the string inside
>> the array of char, so its length is the length of the string plus 1
>> (terminal 0X).
>>
>> Gérard
> Ah, but if x$ is a "string" which you seem to imply includes the
> terminal 0X then when I call
> LEN(x$) in the outer procedure I should also get the value 3 and not
> 2. There seems to be
> an inconsistency.
Here is how I see what happens: when x is passed to an IN parameter, its
address is copied, so formal and actual parameters are identical; when
x$ is passed, a new array of char is created, whose length is just
enough to contain x$ (LEN(x$) + 1), x$ is copied into it and the new
array is passed as actual parameter. In the last case, LEN(y$) = LEN(x$)
and LEN(y) = LEN(x$) + 1.

Gérard

--- BlackBox
--- send subject HELP or UNSUBSCRIBE to blackbox{([at]})nowhere.xy


----boundary-LibPST-iamunique-1716130496_-_-
Content-type: application/rtf
Content-transfer-encoding: base64
Content-Disposition: attachment; filename="rtf-body.rtf"

e1xydGYxXGFuc2lcYW5zaWNwZzEyNTJcZnJvbXRleHQgXGRlZmYwe1xmb250dGJsDQp7XGYwXGZz
d2lzc1xmY2hhcnNldDAgQXJpYWw7fQ0Ke1xmMVxmbW9kZXJuIENvdXJpZXIgTmV3O30NCntcZjJc
Zm5pbFxmY2hhcnNldDIgU3ltYm9sO30NCntcZjNcZm1vZGVyblxmY2hhcnNldDAgQ291cmllciBO
ZXc7fX0NCntcY29sb3J0YmxccmVkMFxncmVlbjBcYmx1ZTA7XHJlZDBcZ3JlZW4wXGJsdWUyNTU7
fQ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ZmVy


----boundary-LibPST-iamunique-1716130496_-_---
Received on Fri Sep 29 2006 - 20:23:47 UTC

This archive was generated by hypermail 2.3.0 : Thu Sep 26 2013 - 06:32:13 UTC