[fpc-pascal]help with pointers?

the reverend the.reverend at coastgames.com
Sat Oct 20 00:48:47 CEST 2001


ok - i can handle that... but i was using the result of assigned to decide
if i should free the memory when i was finished with it, i.e. if p<>nil then
freemem(p);  what should i do instead?

ron.

-----Original Message-----
From: fpc-pascal-admin at deadlock.et.tudelft.nl
[mailto:fpc-pascal-admin at deadlock.et.tudelft.nl]On Behalf Of Jonas Maebe
Sent: Friday, October 19, 2001 5:19 PM
To: fpc-pascal at deadlock.et.tudelft.nl
Subject: Re: [fpc-pascal]help with pointers?




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


_______________________________________________
fpc-pascal maillist  -  fpc-pascal at lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal





More information about the fpc-pascal mailing list