473,806 Members | 2,565 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How can I set a integer array all bits to zero?


#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
Nov 13 '05
15 17670
Jack Klein wrote:

On Wed, 15 Oct 2003 11:49:53 -0400, Eric Sosman <Er*********@su n.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
Nov 13 '05 #11
On Thu, 16 Oct 2003 00:13:26 +0200, "cody" <do************ *********@gmx.d e>
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.

Nov 13 '05 #12
# Padding bits in int values? What reason could made an implementation do
# this?

Star 100.

--
Derk Gwen http://derkgwen.250free.com/html/index.html
If you plan to shoplift, let us know.
Thanks
Nov 13 '05 #13
"Derk Gwen" <de******@HotPO P.com> schrieb im Newsbeitrag
news:vo******** ****@corp.super news.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
Nov 13 '05 #14
On Sat, 18 Oct 2003 01:43:19 +0200, in comp.lang.c , "cody"
<do************ *********@gmx.d e> wrote:
"Derk Gwen" <de******@HotPO P.com> schrieb im Newsbeitrag
news:vo******* *****@corp.supe rnews.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.c om/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 =---
Nov 13 '05 #15
"Mark McIntyre" <ma**********@s pamcop.net> schrieb im Newsbeitrag
news:k6******** *************** *********@4ax.c om...
On Sat, 18 Oct 2003 01:43:19 +0200, in comp.lang.c , "cody"
<do************ *********@gmx.d e> wrote:
"Derk Gwen" <de******@HotPO P.com> schrieb im Newsbeitrag
news:vo******* *****@corp.supe rnews.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
Nov 13 '05 #16

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
6116
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.
1
3149
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()); }
10
5243
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
1
2205
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()
19
7087
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;
46
3699
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);
6
2333
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...
3
9126
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
1
2780
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
0
9719
marktang
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9597
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10372
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,...
0
10110
tracyyun
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...
0
6877
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5546
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...
0
5682
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4329
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
2
3851
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.