On Sun, 19 Apr 1998 11:31:26 +0200 (MEST), Peter Gerwinski wrote:
>According to Kevin A. Foss:
>> [...] It appears that for some reason strings that
>> are defined in procedures/functions are not initialized to a length of
>> 0.
>
>Why should they? Local variables have no predifined value on
>any Pascal compiler I know.
Why? ..because
>For the sake of compatibility to BP, GPC initializes
>all global variables to zero/false/nil/empty string.
I've never seen a compiler predefine undefined variables anywhere
either locally or globally before and I thought GPC would be consistant
in this strangeness by predefining in both places. I didn't realize it
was another Borland "feature". Obviously I assumed wrong.
But isn't this dangerous? It allows the compiler to happily accept
code like:
program test(output);
procedure test1;
var a, b : string (10);
begin
a := a + b
end.
begin
test1;
end.
And then core dump at runtime, or presumeably some other undefined
result.
To me it make more sense to either set local variables to 'don't let
the user shoot himself the foot' values (like global variables) or
actual undefine them so that the compiler can warn/give errors about
it.
>That was twice the same program, and it produces 0 on my (Linux)
>system, too.
Ack, the second program should have been the same as above, except "a
:= a + b;" was replaced with "writeln(length(a));" But that is a moot
point now. :)
Anyway, I thought this was the source of a runtime core-dump I was
having with some TP source , obviously I was wrong and I'll see if I
can better locate what is happening.
-Kevin
--
Kevin A. Foss --- kfoss(a)mint.net