Velocity Reviews > C++ > Zero always == 0000 0000

Zero always == 0000 0000

Tomás
Guest
Posts: n/a

 03-07-2006

> The 2nd methos sets the pointer to "all bits zero" in memory, which may
> or may not represent "all bits zero" in memory.

Typo:

The 2nd method sets the pointer to "all bits zero" in memory, which may
or may not represent a "null pointer".

Rolf Magnus
Guest
Posts: n/a

 03-07-2006
Andrew Koenig wrote:

>> If we talk of straight 0, doesn't the fact that only three
>> representations are accepted (two's complement, one's complement, signed
>> magnitude) serve as the guarantee? Signed magnitude and one's complement
>> have a way to represent -0, but that's not what the OP asked.

>
> Well, I can't find any place in the standard that prohibits sign-magnitude
> notation in which 0 represents negative and 1 represents positive. In
> such a notation, all bits 0 means -0, which is presumably distinguishable
> from 0.

However, this is of no relevance, since the OP didn't ask about signed, but

Guest
Posts: n/a

 03-07-2006

"Tomás" <(E-Mail Removed)> skrev i meddelandet
news:y2dPf.6842\$(E-Mail Removed)...
>
> 2) int* p;
> memset(p,0,sizeof(int*) );
>
>
>
> Actually come to think of it, if we've no guarantee that an unsigned
> numeric type stores its zero value as "all bits zero", then we've
> not
> guarantee that when we pass a zero literal (ie. 0) to memset, that
> it
> will make the memory all bits zero...
>

First, the 0 isn't unsigned, but a signed int.

Also, it is converted to an unsigned char before it is stored. That
presumably takes care of any pad bits, as an unsigned char cannot have
any.

Rolf Magnus
Guest
Posts: n/a

 03-08-2006
Andrew Koenig wrote:

>> If we talk of straight 0, doesn't the fact that only three
>> representations are accepted (two's complement, one's complement, signed
>> magnitude) serve
>> as the guarantee? Signed magnitude and one's complement have a way to
>> represent -0, but that's not what the OP asked.

>
> Well, I can't find any place in the standard that prohibits sign-magnitude
> notation in which 0 represents negative and 1 represents positive.

"The range of nonnegative values of a signed integer type is a subrange of
the corresponding unsigned integer type, and the value representation of
each corresponding signed/unsigned type shall be the same."

I don't see why this shouldn't include the zero value. So an unsigned 0 must
have the same value representation as a signed 0.

Diego Martins
Guest
Posts: n/a

 03-08-2006
are there implementations where null pointers aren't zeros?
which?

Tomás
Guest
Posts: n/a

 03-08-2006
Diego Martins posted:

> are there implementations where null pointers aren't zeros?
> which?
>
>

I don't know any off hand. What I do know is:

A) The Standard permits that a pointer not be all bits zero.

And from that, I'd speculate that they allowed this because there is in
fact a system where pointers aren't all bits zeros.

-Tomás