#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 15 17613
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
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
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."
-- Er*********@sun.com
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
> 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
In article <bm************@ID-176797.news.uni-berlin.de>,
"cody" <do*********************@gmx.de> wrote: cody
[Freeware, Games and Humor]
But definitely not funny.
"cody" <do*********************@gmx.de> wrote: Padding bits in int values? What reason could made an implementation do this?
Parity bits, for example.
--
Irrwahn
(ir*******@freenet.de)
"Eric Sosman" <Er*********@sun.com> wrote in message news:3F***************@sun.com... 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)
On Wed, 15 Oct 2003 11:49:53 -0400, Eric Sosman <Er*********@sun.com>
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
Jack Klein wrote: On Wed, 15 Oct 2003 11:49:53 -0400, Eric Sosman <Er*********@sun.com> wrote in comp.lang.c:
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. [...]
Chapter and verse, please, that C90 guaranteed that all bits 0 is a valid representation of the value 0 for _ANY_ type.
Well, I might be wrong (it's happened before, and will
happen again). The reasoning goes like this: C90 requires
a "pure binary numeration system" for integer types, and
makes no mention of the possibility of non-value bits. If
there are no padding bits, all bits zero must be a valid
representation of an `int' zero.
The weak spot in the argument, of course, is the step
from "C90 doesn't mention padding bits" to the conclusion
"padding bits do not exist." It's logically unsound, I
readily admit. But C90 also omits any mention of behavior
that might result from messing with the representation of
an `int', and C90 also specifically allows a `char' with
all bits zero, so it seems likely -- not conclusive, but
likely -- that C90 doesn't permit padding bits.
By way of analogy (another fallacious, but suggestive
approach), consider that C99 makes no mention of radioactive
bits, or of any behavior that might result from using an
`int' containing one or more radioactive bits. It seems
reasonable to conclude that C99 doesn't permit radioactive
bits, even though Cnext might introduce them.
-- Er*********@sun.com
On Thu, 16 Oct 2003 00:13:26 +0200, "cody" <do*********************@gmx.de>
wrote: Padding bits in int values? What reason could made an implementation do this?
It's unlikely to be done just for fun, but for instance, some obscure
machines have no hardware support for integer operations - everything has to
be done using floating-point. The mantissa bits can store the value, the
sign bit does the obvious, and the exponent becomes padding. On such a
machine, all-bits-zero (including padding) could well be a trap
representation.
-- Mat.
"Derk Gwen" <de******@HotPOP.com> schrieb im Newsbeitrag
news:vo************@corp.supernews.com... # Padding bits in int values? What reason could made an implementation do # this?
Star 100.
Huh?
--
cody
[Freeware, Games and Humor] www.deutronium.de.vu || www.deutronium.tk
On Sat, 18 Oct 2003 01:43:19 +0200, in comp.lang.c , "cody"
<do*********************@gmx.de> wrote: "Derk Gwen" <de******@HotPOP.com> schrieb im Newsbeitrag news:vo************@corp.supernews.com... # Padding bits in int values? What reason could made an implementation do # this?
Star 100.
Huh?
its an implementation.
--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.angelfire.com/ms3/bchambless0/welcome_to_clc.html>
----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==---- http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---
"Mark McIntyre" <ma**********@spamcop.net> schrieb im Newsbeitrag
news:k6********************************@4ax.com... On Sat, 18 Oct 2003 01:43:19 +0200, in comp.lang.c , "cody" <do*********************@gmx.de> wrote:
"Derk Gwen" <de******@HotPOP.com> schrieb im Newsbeitrag news:vo************@corp.supernews.com... # Padding bits in int values? What reason could made an implementation
do # this?
Star 100.
Huh?
its an implementation.
And why do they insert padding bits? What sizes are their integers?
--
cody
[Freeware, Games and Humor] www.deutronium.de.vu || www.deutronium.tk This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: David Lawson |
last post by:
I know how to conver a string to an array of strings, but I need to convert an ascii string to an
array of integers (really unsigned chars). Eg,
$str ="ABC";
needs to convert to something...
|
by: Darsin |
last post by:
Hi all,
I am a new programmer to C# and i am having a following problem.
I want to make a single method which takes a variable length array and
display it contents.
i have defined the method as:...
|
by: Peter Stojkovic |
last post by:
I want store an integer-array of 1000 Values in a blob in a SQL-database.
I will do this every 10 Seconds.
How can I do this ????
What datatypes a have to use ???
Thanks
|
by: Sivaraman.S |
last post by:
Hi,
Can i pass integer array to methodInfo.Invoke(obj,args()). I am able to
pass only string array to this function. This is the code i have written.
Dim myType As Type = objClass.GetType()...
|
by: nileshsimaria |
last post by:
Hi,
I have seen some code were we have array with zero elements (mostly
within structure)
like,
typedef struct foo {
int data
}foo;
|
by: lovecreatesbea... |
last post by:
Do you prefer malloc or calloc?
p = malloc(size);
Which of the following two is right to get same storage same as the
above call?
p = calloc(1, size);
p = calloc(size, 1);
|
by: Army1987 |
last post by:
Reliable sources (whose names I'm not allowed to disclose) told me that on
the next version of the Deathstation (version 10000, or DS10K) an integral
type (they didn't tell which) will have a odd...
|
by: Jerry West |
last post by:
I'd like to get the upper bound index of an integer array. I've tried the
following:
Dim i as Integer
Dim arrayIng() as Integer
i = arrayIng.GetUpperBound
This doesn't work. It seems...
|
by: helios |
last post by:
Hi all,
I'm resolved problem. and I want anybody need me that convert char to array bits
char ConvertChar2ArrayBit(char ch)
{
char Bits;
....
return Bits;
}
for...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
| |