Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | Keith Thompson <kst-u@mib.org> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: zero up memory |
| Date | 2012-01-24 14:13 -0800 |
| Organization | None to speak of |
| Message-ID | <ln4nvk7nq7.fsf@nuthaus.mib.org> (permalink) |
| References | <jfjvmb$sod$1@speranza.aioe.org> <4f1d9169$0$18698$91cee783@newsreader03.highway.telekom.at> <7edb6549-55af-4c5a-91b7-5633b6215246@n6g2000vbz.googlegroups.com> <jfn59h$c3m$1@reader1.panix.com> |
jgk@panix.com (Joe keane) writes:
> In article <7edb6549-55af-4c5a-91b7-5633b6215246@n6g2000vbz.googlegroups.com>,
> Malcolm McLean <malcolm.mclean5@btinternet.com> wrote:
>>All bits zero isn't necessarily a floating point zero, and it isn't
>>necessarily a null pointer. Which makes calloc() pretty useless.
>
> To be honest, i don't think it's a big problem. I have code where i
> simply 'memset' the whole struct, and i'm sure it's been ported to
> twenty machines. No one ever comes back and says 'i ran into that
> thing where you memset the struct, it didn't work'.
>
> So there's practical portable versus paranoid portable.
>
> It's something i just don't care about and i think is not worth spending
> your time on. My employer doesn't care i don't care because, while
> customers may have pretty diverse platforms, they're not geting stuff
> from bizarro world.
>
> Architectures can be different, but there really isn't much variation
> these days in how basic data types [integer, floating-point number,
> pointer] are stored [and how VM basically works].
>
> This is something that people were unsure about 40 years ago; now we
> 'have the answer'. Such things seem sufficient obvious that you don't
> think about it much.
There was a very similar attitude that assumed that dereferencing a null
pointer would give you zero:
int *ptr = NULL;
int *result = *ptr; /* undefined behavior */
assert(result == 0);
because a very popular system happened to guarantee it. A whole lot of
code broke when it was ported to a new system.
There were similar assumptions expressed as "All the world's a VAX"; the
more modern equivalent woudl be "All the world's an x86".
Admittedly there's a more widespread basis for assuming that
floating-point 0.0 and null pointers are represented as all-bits-zero --
but they're still assumptions that are not supported by the standard.
If it turns out that all existing implementatations happen to satisfy
those assumptions, I wouldn't object to adding them as requirements in a
future edition of the C standard. That's exactly what happened with the
assumption that all-bits-zero is a representation of 0 for all integer
types; standards up to and including C99 didn't make that guarantee, but
it was added in one of the Technical Corrigenda and appears in the C11
standard.
Until and unless that happens, I'm not going to count on it -- or if I
do, I'll add a prominent comment documention my assumptions, so future
maintainers will know where to look if things break.
--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
Will write code for food.
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Back to comp.lang.c | Previous | Next — Previous in thread | Find similar | Unroll thread
zero up memory "Mark" <mark_cruzNOTFORSPAM@hotmail.com> - 2012-01-23 10:51 -0500
Re: zero up memory Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-01-23 16:30 +0000
Re: zero up memory Johann Klammer <klammerj@NOSPAM.a1.net> - 2012-01-23 17:57 +0100
Re: zero up memory Kenneth Brody <kenbrody@spamcop.net> - 2012-01-23 12:07 -0500
Re: zero up memory Malcolm McLean <malcolm.mclean5@btinternet.com> - 2012-01-23 09:08 -0800
Re: zero up memory Keith Thompson <kst-u@mib.org> - 2012-01-23 09:22 -0800
Re: zero up memory Malcolm McLean <malcolm.mclean5@btinternet.com> - 2012-01-23 10:13 -0800
Re: zero up memory Keith Thompson <kst-u@mib.org> - 2012-01-23 12:00 -0800
Re: zero up memory Kaz Kylheku <kaz@kylheku.com> - 2012-01-23 20:14 +0000
Re: zero up memory "Joel C. Salomon" <joelcsalomon@gmail.com> - 2012-01-23 16:46 -0500
Re: zero up memory Malcolm McLean <malcolm.mclean5@btinternet.com> - 2012-01-23 14:05 -0800
Re: zero up memory Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-01-23 23:21 +0000
Re: zero up memory Malcolm McLean <malcolm.mclean5@btinternet.com> - 2012-01-24 09:35 -0800
Re: zero up memory Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-01-24 20:56 +0000
Re: zero up memory Keith Thompson <kst-u@mib.org> - 2012-01-24 14:07 -0800
Re: zero up memory Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-01-25 17:38 +0000
Re: zero up memory Johann Klammer <klammerj@NOSPAM.a1.net> - 2012-01-24 23:15 +0100
Re: zero up memory Keith Thompson <kst-u@mib.org> - 2012-01-24 14:31 -0800
Re: zero up memory Kleuske <kleuske@nowhere.net> - 2012-01-25 15:39 +0000
Re: zero up memory Kleuske <kleuske@nowhere.net> - 2012-01-25 15:49 +0000
Re: zero up memory Nick Keighley <nick_keighley_nospam@hotmail.com> - 2012-01-26 03:09 -0800
Re: zero up memory Malcolm McLean <malcolm.mclean5@btinternet.com> - 2012-01-25 13:05 -0800
Re: zero up memory Sjouke Burry <s@b> - 2012-01-25 23:25 +0000
Re: zero up memory Nick Keighley <nick_keighley_nospam@hotmail.com> - 2012-01-26 03:11 -0800
Re: zero up memory Malcolm McLean <malcolm.mclean5@btinternet.com> - 2012-01-26 11:48 -0800
Re: zero up memory gordonb.p79fg@burditt.org (Gordon Burditt) - 2012-03-12 17:55 -0500
Re: zero up memory James Kuyper <jameskuyper@verizon.net> - 2012-03-12 22:10 -0400
Re: zero up memory Eric Sosman <esosman@ieee-dot-org.invalid> - 2012-03-12 23:24 -0400
Re: zero up memory James Kuyper <jameskuyper@verizon.net> - 2012-03-12 23:53 -0400
Re: zero up memory gordonb.pu5nu@burditt.org (Gordon Burditt) - 2012-03-13 00:58 -0500
Re: zero up memory James Kuyper <jameskuyper@verizon.net> - 2012-03-14 11:17 -0400
Re: zero up memory Keith Thompson <kst-u@mib.org> - 2012-01-26 11:19 -0800
Re: zero up memory Kleuske <kleuske@nowhere.net> - 2012-01-27 08:13 +0000
Re: zero up memory Kleuske <kleuske@nowhere.net> - 2012-01-26 14:42 +0000
Re: zero up memory Keith Thompson <kst-u@mib.org> - 2012-01-25 12:33 -0800
Re: zero up memory Kleuske <kleuske@nowhere.net> - 2012-01-26 14:12 +0000
Re: zero up memory James Kuyper <jameskuyper@verizon.net> - 2012-01-24 17:43 -0500
Re: zero up memory Malcolm McLean <malcolm.mclean5@btinternet.com> - 2012-01-24 16:29 -0800
Re: zero up memory James Kuyper <jameskuyper@verizon.net> - 2012-01-24 21:43 -0500
Re: zero up memory Malcolm McLean <malcolm.mclean5@btinternet.com> - 2012-01-24 23:58 -0800
Re: zero up memory Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-01-25 17:52 +0000
Re: zero up memory Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-01-25 17:48 +0000
Re: zero up memory Robert Wessel <robertwessel2@yahoo.com> - 2012-01-25 12:15 -0600
Re: zero up memory blp@cs.stanford.edu (Ben Pfaff) - 2012-01-25 10:35 -0800
Re: zero up memory Robert Wessel <robertwessel2@yahoo.com> - 2012-01-25 17:15 -0600
Re: zero up memory Robert Wessel <robertwessel2@yahoo.com> - 2012-01-25 17:23 -0600
Re: zero up memory "BartC" <bc@freeuk.com> - 2012-01-25 23:51 +0000
Re: zero up memory Robert Wessel <robertwessel2@yahoo.com> - 2012-01-26 18:35 -0600
Re: zero up memory James Kuyper <jameskuyper@verizon.net> - 2012-01-25 13:17 -0500
Re: zero up memory Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-01-23 22:55 +0000
Re: zero up memory jgk@panix.com (Joe keane) - 2012-01-24 20:45 +0000
Re: zero up memory Keith Thompson <kst-u@mib.org> - 2012-01-24 14:13 -0800
csiph-web