Topic: ALL BITS CLEAR OR NOT?
Author: "Mycroft Holmes" <holmes@technologist.REMOVEME.com>
Date: Mon, 14 May 2001 22:47:28 GMT Raw View
nice idea. anybody knows how it's translated in ML when compiled?
--
The set of solutions is never empty.
Two solutions together form a new problem.
-- Mycroft Holmes
> > >
> > > This might be VERY useful, because you could use a memset to fill very
> > > quickly an array with zeroes.
>
> Couldn't the same be achieved by an incomplete initialisation of the
arrays?
>
> double d[100] = { 0.0 }; // I'm not sure whether you have to put the
0.0
> int i[100] = { 0 };
> void* p[100] = { NULL };
>
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html ]
Author: "Homer Meyer" <homer@cqg.com>
Date: Mon, 14 May 2001 23:03:09 GMT Raw View
"Heinz Huber" <hhuber@racon-linz.at> wrote in message
news:3AFBA3C8.231C34D8@racon-linz.at...
>
>
> Homer Meyer wrote:
> >
> > "Mycroft Holmes" <holmes@technologist.REMOVEME.com> wrote in message
> > news:9ddgld$ptd$1@fe1.cs.interbusiness.it...
> [snipped discussion about values of all bits 0]
> > >
> > > This might be VERY useful, because you could use a memset to fill very
> > > quickly an array with zeroes.
> >
> > Prefer std::fill instead of memset. It will always do the right thing,
and
> > it is likely to be optimized to use memset when possible.
> >
> > double d[100];
> > std::fill( d, d+100, 0.0 );
> >
> > int i[100];
> > std::fill( i, i+100, 0 );
> >
> > void* p[100];
> > std::fill( p, p+100, 0 );
> >
> > std::string s[100];
> > std::fill( s, s+100, "default" );
>
> Couldn't the same be achieved by an incomplete initialisation of the
arrays?
>
> double d[100] = { 0.0 }; // I'm not sure whether you have to put the
0.0
> int i[100] = { 0 };
> void* p[100] = { NULL };
Yes, you can do this for all the types above except std::string. However,
this only works for the initialization. If you want to reset the values
sometime later, then you will need to use memset() or std::fill(), and
std::fill() should be preferred over memset().
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html ]
Author: Francis Glassborow <francis.glassborow@ntlworld.com>
Date: Fri, 11 May 2001 22:39:11 GMT Raw View
In article <9ddgld$ptd$1@fe1.cs.interbusiness.it>, Mycroft Holmes
<holmes@technologist.REMOVEME.com> writes
>Usually C/C++ atomic types are defined so that "zero" is an entity with al
>bits clear.
>
>for example it HAPPENS TO ME that
>
>int x = 0; // x = 0x00000000
Yes, that is required for all non-padding bits
>void* p = NULL; // p = 0x00000000
It better not be, there really are systems that use other codes for a
null pointer.
>
>does the standard say anything about that?
Yes, it says that a null pointer is a unique value but nowhere does it
require a specific bit-pattern (and it must not do so)
>
>I think for example the IEEE reference for floating-point numbers requires
>that (float)0 = 0x00..00 and also (double)0.
Maybe but many other systems actually make all bits zero an error
condition for a floating point type.
>
>This might be VERY useful, because you could use a memset to fill very
>quickly an array with zeroes.
That is as maybe, but other forces determined that the rules were
otherwise.
Francis Glassborow ACCU
64 Southfield Rd
Oxford OX4 1PA +44(0)1865 246490
All opinions are mine and do not represent those of any organisation
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html ]
Author: Heinz Huber <hhuber@racon-linz.at>
Date: Sat, 12 May 2001 15:22:09 GMT Raw View
Homer Meyer wrote:
>
> "Mycroft Holmes" <holmes@technologist.REMOVEME.com> wrote in message
> news:9ddgld$ptd$1@fe1.cs.interbusiness.it...
[snipped discussion about values of all bits 0]
> >
> > This might be VERY useful, because you could use a memset to fill very
> > quickly an array with zeroes.
>
> Prefer std::fill instead of memset. It will always do the right thing, and
> it is likely to be optimized to use memset when possible.
>
> double d[100];
> std::fill( d, d+100, 0.0 );
>
> int i[100];
> std::fill( i, i+100, 0 );
>
> void* p[100];
> std::fill( p, p+100, 0 );
>
> std::string s[100];
> std::fill( s, s+100, "default" );
Couldn't the same be achieved by an incomplete initialisation of the arrays?
double d[100] = { 0.0 }; // I'm not sure whether you have to put the 0.0
int i[100] = { 0 };
void* p[100] = { NULL };
IIRC, the remaining (not initialised) members are zero initialised.
Regards,
Heinz
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html ]
Author: Francis Glassborow <francis.glassborow@ntlworld.com>
Date: Sat, 12 May 2001 15:31:16 GMT Raw View
In article <3AFAE040.EEDB0E20@spamcop.net>, Ron Natalie
<ron@spamcop.net> writes
>> int x = 0; // x = 0x00000000
>> void* p = NULL; // p = 0x00000000
>>
>> does the standard say anything about that?
>
>It doesn't say either of the above is true. It is true that it is
>on most popular platforms.
I think that strictly speaking you are right because an implementation
is allowed a -0 in two of the three possible binary representations of
signed integer types, but that is the only exception I am aware of.
Francis Glassborow ACCU
64 Southfield Rd
Oxford OX4 1PA +44(0)1865 246490
All opinions are mine and do not represent those of any organisation
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html ]
Author: "Mycroft Holmes" <holmes@technologist.REMOVEME.com>
Date: Thu, 10 May 2001 17:24:32 GMT Raw View
Usually C/C++ atomic types are defined so that "zero" is an entity with al
bits clear.
for example it HAPPENS TO ME that
int x = 0; // x = 0x00000000
void* p = NULL; // p = 0x00000000
does the standard say anything about that?
I think for example the IEEE reference for floating-point numbers requires
that (float)0 = 0x00..00 and also (double)0.
This might be VERY useful, because you could use a memset to fill very
quickly an array with zeroes.
--
The set of solutions is never empty.
Two solutions together form a new problem.
-- Mycroft Holmes
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html ]
Author: Ron Natalie <ron@spamcop.net>
Date: Thu, 10 May 2001 20:06:54 GMT Raw View
Mycroft Holmes wrote:
>
> Usually C/C++ atomic types are defined so that "zero" is an entity with al
> bits clear.
>
> for example it HAPPENS TO ME that
>
> int x = 0; // x = 0x00000000
> void* p = NULL; // p = 0x00000000
>
> does the standard say anything about that?
It doesn't say either of the above is true. It is true that it is
on most popular platforms.
What it says about NULL (an constant expression evaluating to zero) is
that when converted to the pointer type will be converted to the appropriate
representation for the null pointer of that type.
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html ]
Author: "Homer Meyer" <homer@cqg.com>
Date: Thu, 10 May 2001 20:14:11 GMT Raw View
"Mycroft Holmes" <holmes@technologist.REMOVEME.com> wrote in message
news:9ddgld$ptd$1@fe1.cs.interbusiness.it...
> Usually C/C++ atomic types are defined so that "zero" is an entity with al
> bits clear.
>
> for example it HAPPENS TO ME that
>
> int x = 0; // x = 0x00000000
Note that signed values can be represented using signed magnitude. In that
case there will be two bit values that represent zero. One with all zeroes,
and another with all zeroes except for the sign bit (whichever one that is)
which will be set to one.
> void* p = NULL; // p = 0x00000000
There's no guarantee that the above is true. In C++ a constant value of
zero when converted to a pointer type is converted to the null pointer
constant. But the actual value of the null pointer constant may or may not
be all zeros. Using memset() on an array of pointers to initialize them to
null may or may not have the desrired result.
>
> does the standard say anything about that?
>
> I think for example the IEEE reference for floating-point numbers requires
> that (float)0 = 0x00..00 and also (double)0.
You don't have any guarantee that the system uses IEEE floating point.
Correspondingly, there is no guarantee that the value for zero is all
zeroes.
>
> This might be VERY useful, because you could use a memset to fill very
> quickly an array with zeroes.
Prefer std::fill instead of memset. It will always do the right thing, and
it is likely to be optimized to use memset when possible.
double d[100];
std::fill( d, d+100, 0.0 );
int i[100];
std::fill( i, i+100, 0 );
void* p[100];
std::fill( p, p+100, 0 );
std::string s[100];
std::fill( s, s+100, "default" );
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html ]