Re: Allocating a pointer?         


Author: mimus
Date: May 1, 2008 22:03

On Thu, 01 May 2008 21:22:59 -0700, Barry Schwarz wrote:
> On Thu, 01 May 2008 17:12:16 -0400, mimus hotmail.com>
> wrote:
>
>>On Wed, 30 Apr 2008 18:53:48 -0700, Barry Schwarz wrote:
>>
>
> snip
>
>>>
>>> An automatic variable that is not initialized or assigned to has an
>>> indeterminate value. It is illegal to evaluate this value for any
>>> purpose. Fortunately in this case, this resulted in an obvious error.
>>
>>Ah-ha, it's only static vars that get automagically initialized to zero?
>>(including pointers, to NULL)? so ISO/IEC 9899:1999 6.7.8 constraint 10
>>sez.
>>
>>Furthermore, only calloc() is required to zero out its allocated RAM
>>(warning: not necessarily equivalent to float zero or pointer NULL), while
>>malloc()'s is indeterminate (7.20.3.1 and 3).
>>
>>Live and learn and forget and re-learn! (all auto int types and malloc()
>>ought to automagically initialize to zero, and all pointers to NULL, upon
>>declaration without explicit initialization, as far as I'm concerned,
>>and I find it bizarre that they don't).
>
> You can make a case for a defined object with automatic duration. I
> don't know why you think it should be done for int and pointer but not
> for float, double, short, etc.

I really meant "numeric", and certainly meant double, short, etc. I
forgot about the floats. And since char is equivalent to int . . . .
> But malloc has no idea of the "type" you intend to use the area for. How
> would it know whether to initialize to an int 0 or a pointer NULL (they
> need not have the same bit representation).

It could refer to the (usual) cast employed on the void pointer returned,
and assume int otherwise.

What would a non-zero NULL pointer be, anyway? something like FFFFFFFF?

--

If You Can't Write It In C, It Can't Be Wrote.

RSN
diggit! del.icio.us! reddit!