Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #16068

Re: zero up memory

From Keith Thompson <kst-u@mib.org>
Newsgroups comp.lang.c
Subject Re: zero up memory
Date 2012-01-23 12:00 -0800
Organization None to speak of
Message-ID <lnzkdeur2q.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> <ln4nvmwcz1.fsf@nuthaus.mib.org> <573dd60c-7053-41aa-87ff-6ca03ac92097@k6g2000vbz.googlegroups.com>

Show all headers | View raw


Malcolm McLean <malcolm.mclean5@btinternet.com> writes:
> On Jan 23, 5:22 pm, Keith Thompson <ks...@mib.org> wrote:
>> It's (calloc) useful if the allocated memory doesn't contain any floating-point
>> or pointer subobjects.
>>
> It's too easy to change a structure to add a floating point or pointer
> field, test it, and of course find that the code behaves exactly as
> you want.
> Calloc() is best avoided.

Agreed, mostly -- but if the allocated space contains an array of some
integer type, it's not unreasonable to use calloc() (with a comment).
But yes, there is a risk if the integer array is later changed to a
floating-point array.

(Hmm, I wonder if there are any systems where all-bits-zero is not a
representation of 0.0 for all floating-point types.  Could a future
standard impose such a requirement without breaking existing
implementations?)

-- 
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 | Next in thread | Find similar | Unroll thread


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