C/C++
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
Go Back   Web Development Archives FAQs C/C++

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Web Development Archives Sponsor:
  #1  
Old July 5th, 2008, 06:00 PM
viza
Guest
Dev Archives Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
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

Reply With Quote
  #2  
Old July 5th, 2008, 06:00 PM
Gordon Burditt
Guest
Dev Archives Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
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.
>}


Reply With Quote
  #3  
Old July 5th, 2008, 06:00 PM
viza
Guest
Dev Archives Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
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

Reply With Quote
  #4  
Old July 5th, 2008, 06:39 PM
pete
Guest
Dev Archives Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
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

Reply With Quote
  #5  
Old July 6th, 2008, 07:00 PM
Peter Nilsson
Guest
Dev Archives Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
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

Reply With Quote
  #6  
Old July 8th, 2008, 05:00 PM
Antoninus Twink
Guest
Dev Archives Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
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?


Reply With Quote
Reply

Viewing: Web Development Archives FAQs C/C++ > is a pointer memset to zero necessarily eqal to NULL?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway