Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Re: "memset" vs "= {0}"...Are they equivalent if your initializing variables?

Reply
Thread Tools

Re: "memset" vs "= {0}"...Are they equivalent if your initializing variables?

 
 
Guest
Posts: n/a
 
      09-23-2004
On Wed, 22 Sep 2004 14:02:56 GMT, JKop <(E-Mail Removed)> wrote:


>
>As regards pointers... well let's say that on a certain system, a pointer
>variable takes up 32 bits in memory, as so:
>
>
>0000 0000 0000 0000 0000 0000 0000 0000
>
>
>What you're looking at above is "all bits zero". On Windows, this indicates
>that the pointer is a null pointer. Now imagine a system where the memory
>address 0 is a valid one, ie. it's the first byte of memory, and that on
>this particular system, the null pointer value is:
>
>1111 1111 1111 1111 1111 1111 1111 1111
>
>
>When you write a program with the following line in it:
>
>
>int* p_k = 0;
>
>The compiler doesn't produce code that sets all bits to zero... no no...
>what it does is produce code that sets it to the null pointer value for that
>system (and/or for that type, I believe systems may choose to have different
>null pointer values depending on the type...). But "memset" doesn't have a
>clue about this, all it does is set all bits to zero, which may be a valid
>memory address on some systems, hence it's not portable.
>
>And as regards floating point numbers, implementations aren't obligated to
>represent the value zero as "all bits zero" either.
>
>I don't see how either of the three could be slower/faster than each other,
>they should all yield the same machine code (except maybe the call to
>"memeset" might add overhead if it's not inline...)
>
>
>-JKop




Thank you. Very clear now on why not to always rely on memset.

-Nollie



 
Reply With Quote
 
 
 
 
Ron Natalie
Guest
Posts: n/a
 
      09-23-2004

<(E-Mail Removed)> wrote in message news:udA4d.57488$(E-Mail Removed). ..
> >
> >What you're looking at above is "all bits zero". On Windows, this indicates
> >that the pointer is a null pointer. Now imagine a system where the memory
> >address 0 is a valid one, ie. it's the first byte of memory, and that on
> >this particular system, the null pointer value is:

Actually on lots of machines (including the Windows platforms), location zero is
as good of a memory location as anything else. It's the C/C++ implemenation on
these machines that chooses not to locate anything (accessible) there so it can use all zeros as
the null pointer.

 
Reply With Quote
 
 
 
Reply

Thread Tools

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Tokina, Sigma, Tamron --- Are they equivalent in quality? Dave Digital Photography 40 04-11-2007 12:34 PM
Are they equivalent ? grid C Programming 14 12-18-2005 02:55 AM
Re: "memset" vs "= {0}"...Are they equivalent if your initializing variables? C++ 0 09-23-2004 01:28 PM
"memset" vs "= {0}"...Are they equivalent if your initializing variables? Nollie@runtime.com C++ 17 09-22-2004 06:06 PM
they turn, they power, they make nice pics Keith and Jenn Z. Digital Photography 0 09-21-2003 04:16 AM



Advertisments