----boundary-LibPST-iamunique-721874713_-_-
Content-type: text/plain
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.
>
> Here is the code that shows this.
>
> MODULE Foo;
> IMPORT Out:=StdLog;
>
> PROCEDURE Test*;
> VAR x: ARRAY 32 OF CHAR;
> PROCEDURE Inside (IN y: ARRAY OF CHAR);
> VAR i: INTEGER;
> BEGIN
> Out.String("LEN(y)="); Out.Int(LEN(y)); Out.Ln;
> (* dump the string *)
> FOR i:= 0 TO LEN(y)-1 DO Out.Char(y[i]) END;
> Out.Ln;
> END Inside;
> BEGIN
> x := "HI";
> Out.String("LEN(x$)="); Out.Int(LEN(x$)); Out.Ln;
> Inside(x$);
> END Test;
>
> END Foo.
>
> -Doug Danforth
>
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
--- BlackBox
--- send subject HELP or UNSUBSCRIBE to blackbox{([at]})nowhere.xy
----boundary-LibPST-iamunique-721874713_-_-
Content-type: application/rtf
Content-transfer-encoding: base64
Content-Disposition: attachment; filename="rtf-body.rtf"
e1xydGYxXGFuc2lcYW5zaWNwZzEyNTJcZnJvbXRleHQgXGRlZmYwe1xmb250dGJsDQp7XGYwXGZz
d2lzc1xmY2hhcnNldDAgQXJpYWw7fQ0Ke1xmMVxmbW9kZXJuIENvdXJpZXIgTmV3O30NCntcZjJc
Zm5pbFxmY2hhcnNldDIgU3ltYm9sO30NCntcZjNcZm1vZGVyblxmY2hhcnNldDAgQ291cmllciBO
ZXc7fX0NCntcY29sb3J0YmxccmVkMFxncmVlbjBcYmx1ZTA7XHJlZDBcZ3JlZW4wXGJsdWUyNTU7
fQ0KXHVjMVxwYXJkXHBsYWluXGRlZnRhYjM2MCBcZjBcZnMyMCBEb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