且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

是一个指针memset为零必然eqal为NULL?

更新时间:2023-12-01 08:03:28

文章< 3I ****** *************@newsfe18.ams2&gt ;,

viza< to ****** @ gm-il.com.obviouschange.invalidwrote:
In article <3I*******************@newsfe18.ams2>,
viza <to******@gm-il.com.obviouschange.invalidwrote:

>这个断言是否得到保证?
>Is this assertion guaranteed?



不,都不是。

指针与所有位零和空指针之间没有必然的关系。


另一方面,它在所有广泛的情况下都是正确的 - 使用平台。


- 理查德

-

请记得提及我/你留下的录音带。

No, none of them are. There is no necessary relation between a
pointer with all bits zero and a null pointer.

On the other hand, it''s true on all widely-used platforms.

-- Richard
--
Please remember to mention me / in tapes you leave behind.


>这个断言是否得到保证?
>Is this assertion guaranteed?

> {

void * vptr;

memset(& vptr,0,sizeof vptr) ;

断言(NULL == vptr);
}
>{
void *vptr;
memset( & vptr, 0, sizeof vptr);
assert( NULL == vptr );
}



否。不能保证a的内部表示

空指针是0xdeadbeef,即使在具有32位指针的机器上也是如此。

但它可能是。

No. It is not guaranteed that the internal representation of a
null pointer is 0xdeadbeef, even on a machine with 32-bit pointers.
But it might be.


>这些是什么?
$

sometype * ptr;

memset(& ptr,0,sizeof ptr);

assert((sometype *)NULL == ptr);
>What about these ones?
{
sometype *ptr;
memset( & ptr, 0, sizeof ptr);
assert( (sometype*)NULL == ptr );



No.

No.


assert(NULL ==(void *)ptr);
assert( NULL == (void*)ptr );



No.

No.


>}
>}


2008年7月5日星期六17:52:40 -0500,Gordon Burditt写道:
On Sat, 05 Jul 2008 17:52:40 -0500, Gordon Burditt wrote:

> >这个断言是否得到保证?
{
void * vptr;
memset(& vptr,0,sizeof vptr);
断言(NULL == vptr);
}
>>Is this assertion guaranteed?
{
void *vptr;
memset( & vptr, 0, sizeof vptr);
assert( NULL == vptr );
}



否。无法保证null

指针的内部表示形式为0xdeadbeef,即使在具有32的机器上也是如此位指针。但它可能是


No. It is not guaranteed that the internal representation of a null
pointer is 0xdeadbeef, even on a machine with 32-bit pointers. But it
might be.



那么是否有一些库函数将

size 1的对象数组设置为相同的值?像wmemset()之类的东西,但是对于

大小的指针,甚至更大的结构?


谢谢,

viza

Is there then some library function to set an array of objects of
size 1 to the same value? Something like wmemset() but for things the
size of pointers, or even larger structs?

Thanks,
viza