![]() FreeAndNil will call a class’s free routine and assign nil to the handed pointer (variable of type class).Īlthough it is a good idea, to clear pointers which do not point to valid objects anymore, this can make debugging more difficult since there is no pointer available pointing to the address at which a certain object used to be. An array can have more than one dimension, as in the following examples: type MonthTemps array 1.24, 1.31 of Integer YearTemps array 1.24, 1.31, Jan.Dec of Integer These two array types are built on the same core types. assigned will be replaced by the exact same expression, but conceals the fact a variable is ( implemented as) a pointer. In Pascal you usually do not write expressions like pointerVariable =: nil but use more explanatory identifiers. ![]() de-allocate) the memory that is possibly been occupied by the referenced structure. ![]() assigning nil to a class or pointer variable will not release (i. e. However, there is no comparable mechanism for other types, e. g. The values of the array are lost, if the reference count of dynamicArrayVariable has hit zero. Note, assigning nil to a dynamic array is virtually equivalent to the procedure invocation setLength ( dynamicArrayVariable, 0 ). Nil can be of course assigned to a pointer variable, but also to other types, which are in fact pointers, but their usage is more convenient.ġ program nilDemo ( input, output, stderr ) 2 var 3 loc : pointer 4 chk : array of boolean 5 msg : PChar 6 prc : TProcedure 7 obj : TObject 8 begin 9 // point to nothing 10 loc := nil 11 // clears dynamic array 12 chk := nil 13 // empty string 14 msg := nil 15 // procedural variable not referencing any procedure 16 prc := nil 17 // loses reference to object 18 obj := nil 19 end. Maybe, since the German word „Null“ stands for the digit “zero”, and in order to avoid confusion, or to distinguish between the concept and value, the word nil was chosen.Īt any rate, this does not have any implications while programming. The other suggests, NIL is an English acronym standing for “not in list.” One says, nil is short for the Latin word “nihil” meaning “nothing”. There are two popular explanations of nil’s etymology. The terms “null pointer” and “nil pointer” are used interchangeably, even among Pascal programmers. In FPC it is implemented as pointer ( 0 ) (the numeric value 0), however the programmer is not supposed to use this fact. The reserved word nil represents the special value of a pointer variable not pointing anywhere in particular.
0 Comments
Leave a Reply. |