"All fields or elements of a newly allocated record or array are cleared, which implies that all embedded pointers and procedure variables are initialized to NIL"
and
"Local variables whose types are pointer types or procedure types are initialized to NIL before the body of the procedure is executed."
...but the other local variables are NOT initialized. I think that is a poor language design choice. For example, a record with a BOOLEAN variable which occurs as a local record is not guaranteed to have the value FALSE when first accessed. That necessitates the record implement a method to initialize its variables. I recently kludged a solution for the BOOLEAN case by changing that variable to a pointer type with no fields. The pointer is guaranteed to be NIL on first access within a local declaration of the record. I should not have had to do that.
PROPOSAL
Change Component Pascal to guaranteed that local variables are initialized to ZERO before the body of the procedure is executed where ZERO is defined for all basic data types
Code: Select all
TYPE ZERO
BOOLEAN FALSE
CHAR 0X
INTEGER 0
REAL 0.0
SET {}
ARRAY OF CHAR ""
POINTER NIL
I request that we include 'Guaranteed ZERO' in our next release of BlackBox.
-Doug Danforth