|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
is a pointer memset to zero necessarily eqal to NULL?
Hi all
Is this assertion guaranteed? { void *vptr; memset( & vptr, 0, sizeof vptr); assert( NULL == vptr ); } What about these ones? { sometype *ptr; memset( & ptr, 0, sizeof ptr); assert( (sometype*)NULL == ptr ); assert( NULL == (void*)ptr ); } Thanks, viza |
|
#2
|
|||
|
|||
|
is a pointer memset to zero necessarily eqal to NULL?
>Is this assertion guaranteed?
>{ void *vptr; memset( & vptr, 0, sizeof vptr); assert( NULL == vptr ); >} 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. >What about these ones? >{ sometype *ptr; memset( & ptr, 0, sizeof ptr); assert( (sometype*)NULL == ptr ); No. assert( NULL == (void*)ptr ); No. >} |
|
#3
|
|||
|
|||
|
is a pointer memset to zero necessarily eqal to NULL?
Sat, 05 Jul 2008 17:52:40 -0500, Gordon Burditt wrote:
>>Is this assertion guaranteed? >>{ >void *vptr; >memset( & vptr, 0, sizeof vptr); >assert( NULL == vptr ); >>} > 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. 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 |
|
#4
|
|||
|
|||
|
is a pointer memset to zero necessarily eqal to NULL?
viza wrote:
Hi all > Is this assertion guaranteed? { void *vptr; memset( & vptr, 0, sizeof vptr); assert( NULL == vptr ); } > What about these ones? { sometype *ptr; memset( & ptr, 0, sizeof ptr); assert( (sometype*)NULL == ptr ); assert( NULL == (void*)ptr ); } None of those. These assertions are guaranteed: { void *vptr = 0; sometype *ptr = 0; assert( NULL == vptr ); assert( NULL == 0 ); assert( 0 == vptr ); assert( ptr == vptr ); } -- pete |
|
#5
|
|||
|
|||
|
is a pointer memset to zero necessarily eqal to NULL?
viza wrote:
Is this assertion guaranteed? { void *vptr; memset( & vptr, 0, sizeof vptr); assert( NULL == vptr ); } Have you tried reading the FAQ? viza wrote: Is there then some library function to set an array of objects of size 1 to the same value? Where does the size come into it? Just use a loop static const struct foo foo_zero; /* zero initialised */ for (i = 0; i < N; i++) array[i] = foo_zero; -- Peter |
|
#6
|
|||
|
|||
|
is a pointer memset to zero necessarily eqal to NULL?
8 Jul 2008 at 8:40, Richard Heathfield wrote:
Perhaps when he said "heathfield clique" he actually means "the people in clc who know C". There really are no bounds to your arrogance, are there? |
![]() |
| Viewing: Web Development Archives > FAQs > C/C++ > is a pointer memset to zero necessarily eqal to NULL? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|