Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > How can I set a integer array all bits to zero=?us-ascii?Q?=3F?=

Reply
Thread Tools

How can I set a integer array all bits to zero=?us-ascii?Q?=3F?=

 
 
I wish
Guest
Posts: n/a
 
      10-15-2003

#include <string.h>

int a[ 100 ];

memset( a, 0, sizeof(a) );

Does that guarantee all bits zero?

--
|
___
(-_-)
<| |>---------------------------------- ShepJeng.twbbs.org -------------
/ plum.cs.nccu.edu.tw
 
Reply With Quote
 
 
 
 
Jirka Klaue
Guest
Posts: n/a
 
      10-15-2003
I wish wrote:
> #include <string.h>
>
> int a[ 100 ];
>
> memset( a, 0, sizeof(a) );
>
> Does that guarantee all bits zero?


Depends, C90 no, C99 yes.

Both: int a[100] = {0};

Jirka

 
Reply With Quote
 
 
 
 
Bertrand Mollinier Toublet
Guest
Posts: n/a
 
      10-15-2003
Jirka Klaue wrote:

> I wish wrote:
>
>> #include <string.h>
>>
>> int a[ 100 ];
>>
>> memset( a, 0, sizeof(a) );
>>
>> Does that guarantee all bits zero?

>
>
> Depends, C90 no, C99 yes.
>

You piqued my curiosity. What's up with C99 that the memset guarantees
all bits zero ?

> Both: int a[100] = {0};
>



--
Bertrand Mollinier Toublet
"Lead developer. Iron developer. Copper developer." -- Sean Egan

 
Reply With Quote
 
Eric Sosman
Guest
Posts: n/a
 
      10-15-2003
Jirka Klaue wrote:
>
> I wish wrote:
> > #include <string.h>
> >
> > int a[ 100 ];
> >
> > memset( a, 0, sizeof(a) );
> >
> > Does that guarantee all bits zero?

>
> Depends, C90 no, C99 yes.


There's no "depends" about it: under all versions of
the Standard, `a' is set to all bits zero by this code.

What *does* depend on the Standard version is whether
all bits zero is the same as value zero. In C89/90, an
`int' with all bits zero has the value zero. In C99,
where an `int' is permitted to contain bits that are not
part of its value ("padding bits"), it is possible that a
zero-valued `int' might contain non-zero bits, and it
is also possible that an `int' with all bits zero might
be a "trap representation."

--

 
Reply With Quote
 
Jirka Klaue
Guest
Posts: n/a
 
      10-15-2003
Eric Sosman wrote:
> Jirka Klaue wrote:

....
>>> int a[ 100 ];
>>> memset( a, 0, sizeof(a) );
>>>
>>> Does that guarantee all bits zero?

>>
>>Depends, C90 no, C99 yes.

>
> There's no "depends" about it: under all versions of
> the Standard, `a' is set to all bits zero by this code.
>
> What *does* depend on the Standard version is whether
> all bits zero is the same as value zero.


That's what I meant. Sorry.

> In C89/90, an
> `int' with all bits zero has the value zero. In C99,
> where an `int' is permitted to contain bits that are not
> part of its value ("padding bits"), it is possible that a
> zero-valued `int' might contain non-zero bits, and it
> is also possible that an `int' with all bits zero might
> be a "trap representation."


I thought, it is the other way round. Hmm...

Jirka

 
Reply With Quote
 
cody
Guest
Posts: n/a
 
      10-15-2003
> What *does* depend on the Standard version is whether
> all bits zero is the same as value zero. In C89/90, an
> `int' with all bits zero has the value zero. In C99,
> where an `int' is permitted to contain bits that are not
> part of its value ("padding bits"), it is possible that a
> zero-valued `int' might contain non-zero bits, and it
> is also possible that an `int' with all bits zero might
> be a "trap representation."



Padding bits in int values? What reason could made an implementation do
this?

--
cody

[Freeware, Games and Humor]
www.deutronium.de.vu || www.deutronium.tk


 
Reply With Quote
 
Christian Bau
Guest
Posts: n/a
 
      10-15-2003
In article <bmkgqe$o4pk6$>,
"cody" <> wrote:

> cody
>
> [Freeware, Games and Humor]


But definitely not funny.
 
Reply With Quote
 
Irrwahn Grausewitz
Guest
Posts: n/a
 
      10-15-2003
"cody" <> wrote:

>Padding bits in int values? What reason could made an implementation do
>this?


Parity bits, for example.
--
Irrwahn
()
 
Reply With Quote
 
Jack Klein
Guest
Posts: n/a
 
      10-16-2003
On Wed, 15 Oct 2003 11:49:53 -0400, Eric Sosman <>
wrote in comp.lang.c:

> Jirka Klaue wrote:
> >
> > I wish wrote:
> > > #include <string.h>
> > >
> > > int a[ 100 ];
> > >
> > > memset( a, 0, sizeof(a) );
> > >
> > > Does that guarantee all bits zero?

> >
> > Depends, C90 no, C99 yes.

>
> There's no "depends" about it: under all versions of
> the Standard, `a' is set to all bits zero by this code.
>
> What *does* depend on the Standard version is whether
> all bits zero is the same as value zero. In C89/90, an
> `int' with all bits zero has the value zero. In C99,
> where an `int' is permitted to contain bits that are not
> part of its value ("padding bits"), it is possible that a
> zero-valued `int' might contain non-zero bits, and it
> is also possible that an `int' with all bits zero might
> be a "trap representation."


Chapter and verse, please, that C90 guaranteed that all bits 0 is a
valid representation of the value 0 for _ANY_ type.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++ ftp://snurse-l.org/pub/acllc-c++/faq
 
Reply With Quote
 
Jun Woong
Guest
Posts: n/a
 
      10-16-2003

"Eric Sosman" <> wrote in message news:...
> Jirka Klaue wrote:
> >
> > I wish wrote:
> > > #include <string.h>
> > >
> > > int a[ 100 ];
> > >
> > > memset( a, 0, sizeof(a) );
> > >
> > > Does that guarantee all bits zero?

> >
> > Depends, C90 no, C99 yes.

>
> There's no "depends" about it: under all versions of
> the Standard, `a' is set to all bits zero by this code.


The representations of integer types in C90 are vague because C90
doesn't say much. But we can know that unsigned char in C90 can have
padding bits from a relevant DR, even if it's not the committee's real
intent. Of course, with lack of enough description I think it's
useless to discuss the integer representations in C90.

>
> What *does* depend on the Standard version is whether
> all bits zero is the same as value zero. In C89/90, an
> `int' with all bits zero has the value zero.


If the reason for this is because C90 doesn't mention padding bits for
integer types, the story changed after the DR that I mentioned above
and on which C99's model was based was published.


--
Jun, Woong (mycoboco at hanmail.net)


 
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
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Set all bits to 1 in an array of raw bytes Martin Wells C Programming 95 09-30-2007 06:42 PM
Can we replace 8 bits by 2 bits? Umesh C Programming 22 01-10-2007 12:59 AM
Count maximum contiguous set bits in an integer . Vish C Programming 3 04-29-2005 04:49 PM
8-Bits vs 12 or 16 bits/pixel; When does more than 8 bits count ? Al Dykes Digital Photography 3 12-29-2003 07:08 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57