- Length of string varies!

From: Douglas G. Danforth <"Douglas>
Date: Fri, 29 Sep 2006 15:15:11 -0400

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

Gerard and Alexander,
Ok, I agree with both of you.
It is just something I did not expect.
Yes, if I do LEN(y$) on the inside
and LEN(x$) on the outside then
I get the same results.

Thank you both.

-Doug

Gérard Meunier wrote:
> 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
>
>

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


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

e1xydGYxXGFuc2lcYW5zaWNwZzEyNTJcZnJvbXRleHQgXGRlZmYwe1xmb250dGJsDQp7XGYwXGZz
d2lzc1xmY2hhcnNldDAgQXJpYWw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czogd2hlbiB4IGlzIHBhc3NlZCB0byBh
biBJTiBwYXJhbWV0ZXIsIFxwYXINCj4gaXRzIGFkZHJlc3MgaXMgY29waWVkLCBzbyBmb3JtYWwg
YW5kIGFjdHVhbCBwYXJhbWV0ZXJzIGFyZSBpZGVudGljYWw7IFxwYXINCj4gd2hlbiB4JCBpcyBw
YXNzZWQsIGEgbmV3IGFycmF5IG9mIGNoYXIgaXMgY3JlYXRlZCwgd2hvc2UgbGVuZ3RoIGlzIFxw
YXINCj4ganVzdCBlbm91Z2ggdG8gY29udGFpbiB4JCAoTEVOKHgkKSArIDEpLCB4JCBpcyBjb3Bp
ZWQgaW50byBpdCBhbmQgdGhlIFxwYXINCj4gbmV3IGFycmF5IGlzIHBhc3NlZCBhcyBhY3R1YWwg
cGFyYW1ldGVyLiBJbiB0aGUgbGFzdCBjYXNlLCBMRU4oeSQpID0gXHBhcg0KPiBMRU4oeCQpIGFu
ZCBMRU4oeSkgPSBMRU4oeCQpICsgMS5ccGFyDQo+XHBhcg0KPiBHXCdlOXJhcmRccGFyDQo+XHBh
cg0KPiAtLS0gQmxhY2tCb3hccGFyDQo+IC0tLSBzZW5kIHN1YmplY3QgSEVMUCBvciBVTlNVQlND
UklCRSB0byBibGFja2JveEBvYmVyb24uY2hccGFyDQo+XHBhcg0KPlxwYXINClxwYXINCi0tLSBC
bGFja0JveFxwYXINCi0tLSBzZW5kIHN1YmplY3QgSEVMUCBvciBVTlNVQlNDUklCRSB0byBibGFj
a2JveEBvYmVyb24uY2hccGFyDQp9fQCQTkAs


----boundary-LibPST-iamunique-496127042_-_---
Received on Fri Sep 29 2006 - 21:15:11 UTC

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