[fpc-pascal]help with pointers?
Jonas Maebe
jonas at zeus.rug.ac.be
Sat Oct 20 00:18:45 CEST 2001
On Fri, 19 Oct 2001, the reverend wrote:
> given the following:
>
> -------------
> program test;
> var p: ^word;
> -------------
>
> p is unassigned as expected, but:
>
> ------------
> program test;
>
> procedure temp;
> var p: ^word;
> -------------
>
> why is p assigned? shouldn't p be nil in this case also?
First of all, assigned() just checks if the value of the pointer is
different from nil (= 0). If it is, it reports true, otherwise false.
Next, global data is automatically initialized by the linker to 0. Global
data is allocated on the stack when you call a routine adn this memory is
not zeroed. One reason for this is that it would probably significantly
slow down your program, since these variables are allocated every time you
call said procedure/function.
As a general rule of the thumb, you should regard any variable which you
haven't assigned a value yet hjust like that: uninitialized, which means
their value is undefined.
Jonas
More information about the fpc-pascal
mailing list