[fpc-pascal] How are Assigned, Free, Nil and Destroy related?

Frank Peelo f26p at eircom.net
Sun Oct 23 20:52:50 CEST 2011


On 22/10/11 10:01, Mark Morgan Lloyd wrote:
> Felipe Monteiro de Carvalho wrote:
>
>> Free is how you release the memory allocated for a object. Free calls
>> Destroy. Never call Destroy manually. When you implement the
>> destructor you always implement Destroy, never change Free.
>
> A number of years ago, Matthew Jones's wife looked over his shoulder 
> and caught him using Create and Destroy. "Bit violent, isn't it?" When 
> he told the story somebody else pointed out that he should be using 
> Create and Free, I find this anecdote makes it easy to remember.
>
>> Nil is not a routine, it is a value, it means that the object is
>> empty, it does not exist / is not allocated. Nil in existing
>> implementations that I know is represented by the value zero.
>
> I've once seen a compiler using a non-zero value, I think it was the 
> first Logitech protected-mode Modula-2 and it used ffff:0000. Apart 
> from that I think that C specifies that nil has a bit pattern of all 
> zeros, and anything with even the slightest interest in compatibility 
> sticks to this as a convention.
>
Almost -- In C, NULL doesn't have to be all zeroes internally, but the 
value 0 in the source code represents the NULL pointer. The compiler is 
allowed to convert (void*)0 to a different bit pattern if the hardware 
requires it, but you'd need a pretty good reason to make life that 
complicated. So it would be a rare compiler that did that.

If I recall corerctly, that Modula-2 value for nil was the address the 
8086 jumped to when released from RESET. So jumping through a pointer 
with value nil would be something you would notice pretty much immediately.

FP




More information about the fpc-pascal mailing list