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


Groups > comp.lang.c > #34560

Re: How much memory does malloc(0) allocate?

From Keith Thompson <kst-u@mib.org>
Newsgroups comp.lang.c
Subject Re: How much memory does malloc(0) allocate?
Date 2013-07-25 19:01 -0700
Organization None to speak of
Message-ID <ln4nbi13ly.fsf@nuthaus.mib.org> (permalink)
References <kssf78$oo9$1@dont-email.me>

Show all headers | View raw


Lynn McGuire <lmc@winsim.com> writes:
> How much memory does malloc(0) allocate?
>     http://prog21.dadgum.com/179.html
>
> Interesting!
>
> Associated conversation on Reddit:
>     http://www.reddit.com/r/programming/comments/1iv9nz/how_much_memory_does_malloc0_allocate/

C11 7.22.3p1:

    If the size of the space requested is zero, the behavior is
    implementation-defined: either a null pointer is returned, or
    the behavior is as if the size were some nonzero value, except
    that the returned pointer shall not be used to access an object.

There's really not much more to say about it, and well-written code
shouldn't care whether malloc(0) returns a null pointer or not.

-- 
Keith Thompson (The_Other_Keith) kst-u@mib.org  <http://www.ghoti.net/~kst>
Working, but not speaking, for JetHead Development, Inc.
"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 | NextPrevious in thread | Next in thread | Find similar


Thread

How much memory does malloc(0) allocate? Lynn McGuire <lmc@winsim.com> - 2013-07-25 19:23 -0500
  Re: How much memory does malloc(0) allocate? Eric Sosman <esosman@comcast-dot-net.invalid> - 2013-07-25 21:14 -0400
  Re: How much memory does malloc(0) allocate? Barry Schwarz <schwarzb@dqel.com> - 2013-07-25 18:37 -0700
  Re: How much memory does malloc(0) allocate? Keith Thompson <kst-u@mib.org> - 2013-07-25 19:01 -0700
    Re: How much memory does malloc(0) allocate? Eric Sosman <esosman@comcast-dot-net.invalid> - 2013-07-25 22:25 -0400
      Re: How much memory does malloc(0) allocate? Kleuske <kleuske@nowhere.net> - 2013-07-26 14:55 +0000
        Re: How much memory does malloc(0) allocate? Eric Sosman <esosman@comcast-dot-net.invalid> - 2013-07-26 13:43 -0400
          Re: How much memory does malloc(0) allocate? Rosario1903 <Rosario@invalid.invalid> - 2013-07-26 20:54 +0200
            Re: How much memory does malloc(0) allocate? Eric Sosman <esosman@comcast-dot-net.invalid> - 2013-07-26 15:08 -0400
            Re: How much memory does malloc(0) allocate? Bart van Ingen Schenau <bart@ingen.ddns.info.invalid> - 2013-07-27 08:52 +0000
              Re: How much memory does malloc(0) allocate? Rosario1903 <Rosario@invalid.invalid> - 2013-07-27 11:24 +0200
                Re: How much memory does malloc(0) allocate? Eric Sosman <esosman@comcast-dot-net.invalid> - 2013-07-27 08:11 -0400
          Re: How much memory does malloc(0) allocate? Kleuske <kleuske@nowhere.net> - 2013-07-27 10:11 +0000
          Re: How much memory does malloc(0) allocate? Kleuske <kleuske@nowhere.net> - 2013-07-27 10:34 +0000
            Re: How much memory does malloc(0) allocate? Eric Sosman <esosman@comcast-dot-net.invalid> - 2013-07-27 08:37 -0400
              Re: How much memory does malloc(0) allocate? Kleuske <kleuske@nowhere.net> - 2013-07-27 16:45 +0000
          Re: How much memory does malloc(0) allocate? Phil Carmody <thefatphil_demunged@yahoo.co.uk> - 2013-07-30 14:40 +0300
            Re: How much memory does malloc(0) allocate? Kleuske <kleuske@nowhere.net> - 2013-07-30 11:57 +0000
              Re: How much memory does malloc(0) allocate? Phil Carmody <thefatphil_demunged@yahoo.co.uk> - 2013-08-01 15:57 +0300
            Re: How much memory does malloc(0) allocate? David Thompson <dave.thompson2@verizon.net> - 2013-08-04 22:26 -0400
              Re: How much memory does malloc(0) allocate? Eric Sosman <esosman@comcast-dot-net.invalid> - 2013-08-05 07:07 -0400
                Re: How much memory does malloc(0) allocate? Kleuske <kleuske@nowhere.net> - 2013-08-06 08:44 +0000
              Re: How much memory does malloc(0) allocate? Kleuske <kleuske@nowhere.net> - 2013-08-05 11:29 +0000
    Re: How much memory does malloc(0) allocate? Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2013-07-25 22:34 -0400
    Re: How much memory does malloc(0) allocate? Malcolm McLean <malcolm.mclean5@btinternet.com> - 2013-07-26 03:39 -0700
      Re: How much memory does malloc(0) allocate? James Kuyper <jameskuyper@verizon.net> - 2013-07-26 07:58 -0400
        Re: How much memory does malloc(0) allocate? James Kuyper <jameskuyper@verizon.net> - 2013-07-26 13:27 -0400
          Re: How much memory does malloc(0) allocate? Rosario1903 <Rosario@invalid.invalid> - 2013-07-26 20:32 +0200
          Re: How much memory does malloc(0) allocate? Eric Sosman <esosman@comcast-dot-net.invalid> - 2013-07-26 15:06 -0400
            Re: How much memory does malloc(0) allocate? James Kuyper <jameskuyper@verizon.net> - 2013-07-26 15:12 -0400
      Re: How much memory does malloc(0) allocate? Ike Naar <ike@faeroes.freeshell.org> - 2013-07-26 12:26 +0000
    Re: How much memory does malloc(0) allocate? christian.bau@cbau.wanadoo.co.uk - 2013-07-26 04:30 -0700
    Re: How much memory does malloc(0) allocate? Lynn McGuire <lmc@winsim.com> - 2013-07-26 09:57 -0500
    Re: How much memory does malloc(0) allocate? Keith Thompson <kst-u@mib.org> - 2013-07-26 09:30 -0700
      Re: How much memory does malloc(0) allocate? Malcolm McLean <malcolm.mclean5@btinternet.com> - 2013-07-26 16:17 -0700
      Re: How much memory does malloc(0) allocate? Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2013-07-26 20:23 -0600
        Re: How much memory does malloc(0) allocate? James Kuyper <jameskuyper@verizon.net> - 2013-07-26 23:55 -0400
  Re: How much memory does malloc(0) allocate? Siri Cruise <chine.bleu@yahoo.com> - 2013-07-26 04:27 -0700
  Re: How much memory does malloc(0) allocate? Rosario1903 <Rosario@invalid.invalid> - 2013-07-26 19:33 +0200
    Re: How much memory does malloc(0) allocate? Rosario1903 <Rosario@invalid.invalid> - 2013-07-26 20:32 +0200
  Re: How much memory does malloc(0) allocate? "Heinrich Wolf" <invalid@invalid.invalid> - 2013-07-28 12:35 +0200
    Re: How much memory does malloc(0) allocate? James Kuyper <jameskuyper@verizon.net> - 2013-07-28 09:01 -0400
      Re: How much memory does malloc(0) allocate? Eric Sosman <esosman@comcast-dot-net.invalid> - 2013-07-28 09:46 -0400
        Re: How much memory does malloc(0) allocate? Geoff <geoff@invalid.invalid> - 2013-07-28 11:33 -0700
          Re: How much memory does malloc(0) allocate? Keith Thompson <kst-u@mib.org> - 2013-07-28 12:38 -0700
          Re: How much memory does malloc(0) allocate? Richard Damon <Richard@Damon-Family.org> - 2013-07-28 15:44 -0400
          Re: How much memory does malloc(0) allocate? Eric Sosman <esosman@comcast-dot-net.invalid> - 2013-07-28 16:01 -0400
          Re: How much memory does malloc(0) allocate? James Kuyper <jameskuyper@verizon.net> - 2013-07-28 16:16 -0400
  Re: How much memory does malloc(0) allocate? BGB <cr88192@hotmail.com> - 2013-07-28 15:59 -0500
    Re: How much memory does malloc(0) allocate? Eric Sosman <esosman@comcast-dot-net.invalid> - 2013-07-28 18:09 -0400
      Re: How much memory does malloc(0) allocate? BGB <cr88192@hotmail.com> - 2013-07-28 19:15 -0500
        Re: How much memory does malloc(0) allocate? Richard Damon <Richard@Damon-Family.org> - 2013-07-28 20:37 -0400
          Re: How much memory does malloc(0) allocate? Eric Sosman <esosman@comcast-dot-net.invalid> - 2013-07-28 20:39 -0400
          Re: How much memory does malloc(0) allocate? BGB <cr88192@hotmail.com> - 2013-07-28 21:31 -0500
        Re: How much memory does malloc(0) allocate? Malcolm McLean <malcolm.mclean5@btinternet.com> - 2013-07-29 03:53 -0700
          Re: How much memory does malloc(0) allocate? BGB <cr88192@hotmail.com> - 2013-07-29 11:53 -0500
      Re: How much memory does malloc(0) allocate? Robert Wessel <robertwessel2@yahoo.com> - 2013-07-28 19:18 -0500
        Re: How much memory does malloc(0) allocate? Lynn McGuire <lmc@winsim.com> - 2013-07-29 14:42 -0500
          Re: How much memory does malloc(0) allocate? James Kuyper <jameskuyper@verizon.net> - 2013-07-29 16:22 -0400
          Re: How much memory does malloc(0) allocate? James Kuyper <jameskuyper@verizon.net> - 2013-07-29 16:29 -0400
            Re: How much memory does malloc(0) allocate? Keith Thompson <kst-u@mib.org> - 2013-07-29 14:59 -0700
              Re: How much memory does malloc(0) allocate? glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2013-07-30 01:18 +0000
                Re: How much memory does malloc(0) allocate? Keith Thompson <kst-u@mib.org> - 2013-07-29 18:58 -0700
                Re: How much memory does malloc(0) allocate? Geoff <geoff@invalid.invalid> - 2013-07-29 20:24 -0700
                Re: How much memory does malloc(0) allocate? Malcolm McLean <malcolm.mclean5@btinternet.com> - 2013-07-30 02:34 -0700
                Re: How much memory does malloc(0) allocate? James Kuyper <jameskuyper@verizon.net> - 2013-07-30 07:42 -0400
                Re: How much memory does malloc(0) allocate? "James Harris \(es\)" <james.harris.1@gmail.com> - 2013-07-30 13:02 +0100
                Re: How much memory does malloc(0) allocate? BGB <cr88192@hotmail.com> - 2013-07-30 13:13 -0500
                Re: How much memory does malloc(0) allocate? Ian Collins <ian-news@hotmail.com> - 2013-07-31 07:44 +1200
                Re: How much memory does malloc(0) allocate? Keith Thompson <kst-u@mib.org> - 2013-07-30 14:33 -0700
                Re: How much memory does malloc(0) allocate? Lynn McGuire <lmc@winsim.com> - 2013-07-30 12:11 -0500
                Re: How much memory does malloc(0) allocate? glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2013-07-30 21:57 +0000
                Re: How much memory does malloc(0) allocate? James Kuyper <jameskuyper@verizon.net> - 2013-07-30 18:02 -0400
          Re: How much memory does malloc(0) allocate? Ike Naar <ike@ukato.freeshell.org> - 2013-07-29 21:50 +0000

csiph-web