#include <string.h>
int a[ 100 ];
memset( a, 0, sizeof(a) );
Does that guarantee all bits zero?
--
|
___
(-_-)
<| |>---------------------------------- ShepJeng.twbbs. org -------------
/ plum.cs.nccu.ed u.tw 15 17669
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.d e> wrote: cody
[Freeware, Games and Humor]
But definitely not funny.
"cody" <do************ *********@gmx.d e> wrote: Padding bits in int values? What reason could made an implementation do this?
Parity bits, for example.
--
Irrwahn
(ir*******@free net.de)
"Eric Sosman" <Er*********@su n.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*********@su n.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.l earn.c-c++ ftp://snurse-l.org/pub/acllc-c++/faq 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 like this:
$buf = array(0x41, 0x42, 0x43);
Anyone know how? I haven't been able to find a way.
|
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:
public void DisplayVals(params object objArray) {
foreach (object o in objArray)
Console.WriteLine(o.ToString());
}
|
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()
Dim myMethod As MethodInfo = myType.GetMethod("strFnName")
myMethod.Invoke(objClass, Args)
here "strFnName" is the function name and args() is the string array. args()
|
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 parity bit, that is a bit
which is set if an even number of value/sign bits are set, and unset
otherwise. If the parity is wrong, the representation is a trap, and they
didn't tell me how it is handled (and they won't even have to tell this
when...
|
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 GetUpperBound behaves more like a function in
that it wants a passed parameter. Is there not a property similar to VB6
|
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 example: A
after converted: 10000010
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |