On Sep 23, 4:25pm, Clive Page wrote:
> Subject: Re: A rare behaivor of pointers
> On Wed, 23 Sep 1998, Peter Shenkin wrote:
>
> > Pointers are like other variables, in the sense that they have
> > to be initialized before they are used. Asking why an uninitialized
> > pointer isn't automatically nullified is like asking why an unitialized
> > integer isn't automatically set to zero.
>
> With respect, I don't think the two case are quite equivalent. A pointer
> does have a well-defined null state, a variable doesn't (unfortunately).
>
> I recall a system I used long ago (CDC Cyber series) where one could
> preset all numerical variables to an illegal value that would cause a
> run-time error if the variable was used before set. This was a Jolly Good
> Thing, in my opinion, as it greatly assisted debugging.
SGI has this; it's called "-trapuv" ("trap uninitialized variables").
It actually sets the storage to a NaN pattern, which causes an
FPE if it's a float or double, a segv usulally if it's a pointer, but
unfortunately generally just gives bad results if it's an int.
> Now the IEEE std for floating-point does have NaN values which some
> systems treat the same way, but not all. But there isn't anything similar
> for integers on most systems. If there _were_ a null value for types of
> object I think it would be very useful for the Fortran Standard to specify
> that all variables should be initialised to it. Since there _is_ one for
> pointers, I would support setting them to null initially by default.
>
> The current problems are compounded by the lack of any way of presetting a
> pointer to null in F90, fortunately fixed in F95.
...
I do agree that it is sensible, semantically, to create all
pointers in the NULLIFIED state; this might be hard in some cases,
and there might be gotchas, and there might be times where it's
just a waste of CPU.
However, I do stand by my intial assertion that conceptually,
assigning a target, or the targetless state, is like assigning
a value to a variable. In C, they are syntactically equivalent
as well; of course, F ain't C, but I do feel that the conceptual
equivalence holds even in F (and underneath, nullifying a pointer
probably does involve setting some data structure element to
a particular value in just about all implementations).
Personally, I wouldn't be against initializing all pointers to
NULL() by default in the Standard; short of this, I think
a cmdline flag to do this might be useful for debugging, as
a Q-of-I issue -- though I realize that this is different from
being able to rely on the behavior.
-P.
--
*** "Freedom's just another word for nothing left to lose." (B. Yeltsin)***
*Peter Shenkin; Chemistry, Columbia U.; [log in to unmask] (212)854-5143*
*MacroModel WWW page: http://www.columbia.edu/cu/chemistry/mmod/mmod.html *
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|