Just to add confirmation to what Frank and Gale have said. In the following "foo" example, yes, the string length is undefined. Yes it is supposed to be an error, and is defined as an error in ISO and Extended Pascal standards. No, it's probably not desirable to start automatically initializing everything; it would be costly in time and space and generally an error-free program will do it's own initialization when needed. And sure, GPC does not detect undefined values, in fact, very very few "compilers" (actually runtimes) do detect undefined values. (Our "Dr. Pascal" interpreter is one of the few systems that does, and it costs a lot of runtime overhead and complexity.) It's very reasonable for GPC to not try to do this.
Willett Kempton Visible Software
On 7 Aug 2005, at 21:21, Frank Heckenbach wrote:
Russell Whitaker wrote:
The capacity, OTOH, is initialized, and must be in order for the string to work at all.
Would it be reasonable to define the length to be 0 as the default initialization?
It would be nonstandard. Basically the same question as defining default values for other types. The programmer can do this explicitly (String (n) value '') if wanted.
Otherwise the following should produce an error but dosen't:
program foo; var s : string( 500 ); begin writeln( length(s) ); end.
As I said, GPC doesn't check for using undefined values at all. (Currently, and this isn't going to change soon, as this is not exactly trivial to implement in general ...)
Frank