Maurice Lombardi wrote:
Indeed, in this case it's more surprising, but actually, the alternative would be surprising in even more subtle ways. Then, e.g., these two calls could produce different results:
var a: String (10);
procedure p (s: String); begin ... end;
begin a := 'foo'; p (a); p ('foo'); end.
This would clearly violate the properties of value parameters.
You are right. Still I would consider as "more natural" the rule: with a value String parameter (without explicit capacity),
- copy the original string with its capacity if it has one: p(a)
- supply capacity = length if not : p('foo')
1. How does this differ from Pascal's original assumption (which violates value parameter properties, as I explained, as you admit is right)?
2. How does this really solve Pascal's problem? In particular, consider this example from my previous mail:
: [T]his will work then [i.e., the way it's now], (which wouldn't : when passing the capacity): : : var a: String (5); : : begin : a := 'foo'; : p (a, 10); : end. : : In your case, it could only pad to 5 chars. With the local variable : it can pad to 10 chars as I suppose it should.
(And `p ('foo', 10)' could not pad at all -- just like now.)
"more natural" means that I would be able to understand directly the surprising behaviour observed originally by Pascal, without having to ask to somebody who knows so well the internals of gpc.
It's not really GPC internals. It's the behaviour specified in the EP standard.
Frank