Article View: comp.std.c
Article #4820Re: fast block zeroing, how defined?
From: Tanmoy Bhattacharya
Date: Tue, 13 Feb 1996 19:43
Date: Tue, 13 Feb 1996 19:43
48 lines
2613 bytes
2613 bytes
In article <4fqaj4$2qu@fu-berlin.de> axl@zedat.fu-berlin.de (Axel
Thimm) writes:
<snip>
in <string.h> there is (at least in GNU C) a function
void bzero(void *pointer, int length);
which fills the memory from pointer to pointer+length-1 with zeros. This
can be used for fast array zeroing, but I do not know how well this is
defined in ANSI C.
[Q1] Is bzero part of ANSI?
No.
[Q2] Are the representation of zeros in intergral types defined
as multiple "char" zeros? (This is true in all the implementations
I know of, but it should be also defined in the standard that way)
All the significant bits of zero of an integral type, except for the
highest, must be zero. Unfortunately, it has been decided that not all
bits are significant. I conclude that some of them can be used for
parity checks, and I conclude the top bit being zero (with others
being zero) can result in an invalid value. I am not familiar enough
with the standard to guarantee my conclusions have any merit: but I
would like to know why they are wrong if they are.
Provisionally, I would not memset or calloc on non-character integral
types if absolute adherence to the standard were a criterion.
[Q3] What does the standard say about float representations of zero?
Nothing.
What should the casting to a char[sizeof(float)] and vice versa do?
You can't cast to an array type.
(In case that 0.0f casted to a char array (or the pointers thereof, to
be precise) returns {0, 0, 0, 0} (in a 4-byte float, i.e.
sizeof(float)==4) then bzero could be used to zero float arrays, too.)
Cheers
Tanmoy--
tanmoy@qcd.lanl.gov(128.165.23.46) DECNET: BETA::"tanmoy@lanl.gov"(1.218=1242)
Tanmoy Bhattacharya O:T-8(MS B285)LANL,NM87545 H:#9,3000,Trinity Drive,NM87544
Others see <gopher://yaleinfo.yale.edu:7700/00/Internet-People/internet-mail>,
<http://alpha.acast.nova.edu/cgi-bin/inmgq.pl>or<ftp://csd4.csd.uwm.edu/pub/
internetwork-mail-guide>. -- <http://nqcd.lanl.gov/people/tanmoy/tanmoy.html>
fax: 1 (505) 665 3003 voice: 1 (505) 665 4733 [ Home: 1 (505) 662 5596 ]
Technical Details
Message-ID:
<TANMOY.96Feb13124302@qcd.lanl.gov>Path:
arc1-ca.pugleaf.net!newshost.lanl.gov!tanmoyReferences:
<4fqaj4$2qu@fu-berlin.de>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!newshost.lanl.gov!tanmoy From: tanmoy@qcd.lanl.gov (Tanmoy Bhattacharya) Newsgroups: comp.std.c Subject: Re: fast block zeroing, how defined? Date: 13 Feb 1996 19:43:02 GMT Organization: Los Alamos National Laboratory Message-ID: <TANMOY.96Feb13124302@qcd.lanl.gov> References: <4fqaj4$2qu@fu-berlin.de> NNTP-Posting-Host: qcd.lanl.gov Mime-Version: 1.0 Content-Type: text In-reply-to: axl@zedat.fu-berlin.de's message of Tue, 13 Feb 1996 15:29:21 GMT