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


Groups > comp.lang.c > #35423

Re: size of

From Keith Thompson <kst-u@mib.org>
Newsgroups comp.lang.c
Subject Re: size of
Date 2013-08-17 13:35 -0700
Organization None to speak of
Message-ID <lnbo4wjbsp.fsf@nuthaus.mib.org> (permalink)
References <kuduo2$a74$1@speranza.aioe.org> <kudutp$g64$1@dont-email.me> <kum7po$g06$1@speranza.aioe.org> <kumnja$nir$1@dont-email.me> <43986715-639e-4a1a-84c0-a6b0bcf686e5@googlegroups.com>

Show all headers | View raw


Malcolm McLean <malcolm.mclean5@btinternet.com> writes:
> On Saturday, August 17, 2013 3:36:27 AM UTC+1, Eric Sosman wrote:
>> 	int *ptr = malloc(42 * sizeof *ptr);
>>
>>      - The fourth is an example of the allocation pattern favored by
>>      thoughtful C programmers, but it *relies* on `*ptr' not being
>>      evaluated by `sizeof'. (If `*ptr' were evaluated at that moment,
>>      before it had been initialized, the effect of trying to
>>      dereference the garbage pointer would be undefined).
>> 
> No, that's how a geek writes an allocation call.

Yes, it is.

Unless you meant "geek" to be a derogatory term, in which case you're
spewing nonsense.

> What he's thinking is that if ptr is changed to a long *, the code
> won't break. And he's right. It is a genuine advantage. But the price
> is a construct which is meaningless to human reader, unless he's very
> familiar with C.  As you say it looks like *ptr should yield
> something, but ptr is currently wild. Then we've got another use of
> the * operator. Finally, it's not obvious that sizeof is not an
> identifier, it's not clear what its scope is.  Could sizeof * be
> sizeof a wildcard, which is somehow applied to ptr?
>
> ptr = malloc(42 * sizeof(int));
>
> is far more readable. Everyone can see that we're allocating a space for 42
> ints. 

So we should write fragile code so that readers who are unfamiliar with
the language can read it a little more easily?  But you're assuming they
know what "malloc" means, and that "=" means assignment and "*" means
multiplication.

The solution to not understanding what
    int *ptr = malloc(42 * sizeof *ptr);
means is to *learn* what
    int *ptr = malloc(42 * sizeof *ptr);
means.  You apparently understand it yourself.  Why do you want to
impose limits on others?

-- 
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

size of Raj Pashwar <raj121190@hotmail.NOSPAM.com> - 2013-08-13 18:43 +0000
  Re: size of Stephen Sprunk <stephen@sprunk.org> - 2013-08-13 13:46 -0500
    Re: size of Raj Pashwar <raj121190@hotmail.NOSPAM.com> - 2013-08-16 22:06 +0000
      Re: size of Azazel <azazel@remove.azazel.net> - 2013-08-16 17:32 -0500
      Re: size of Stephen Sprunk <stephen@sprunk.org> - 2013-08-16 18:10 -0500
        Re: size of Keith Thompson <kst-u@mib.org> - 2013-08-16 17:11 -0700
          Re: size of Raj Pashwar <raj121190@hotmail.NOSPAM.com> - 2013-08-17 09:11 +0000
            Re: size of Shao Miller <sha0.miller@gmail.com> - 2013-08-17 05:38 -0400
            Re: size of James Kuyper <jameskuyper@verizon.net> - 2013-08-17 09:00 -0400
      Re: size of James Kuyper <jameskuyper@verizon.net> - 2013-08-16 21:43 -0400
      Re: size of Eric Sosman <esosman@comcast-dot-net.invalid> - 2013-08-16 22:36 -0400
        Re: size of Malcolm McLean <malcolm.mclean5@btinternet.com> - 2013-08-17 03:08 -0700
          Re: size of James Kuyper <jameskuyper@verizon.net> - 2013-08-17 08:57 -0400
          Re: size of Keith Thompson <kst-u@mib.org> - 2013-08-17 13:35 -0700
            Re: size of Malcolm McLean <malcolm.mclean5@btinternet.com> - 2013-08-17 15:17 -0700
              Re: size of Keith Thompson <kst-u@mib.org> - 2013-08-17 17:06 -0700
          Re: size of Richard Damon <Richard@Damon-Family.org> - 2013-08-17 18:27 -0400
          Re: size of Tim Rentsch <txr@alumni.caltech.edu> - 2013-08-21 00:29 -0700
            Re: size of Malcolm McLean <malcolm.mclean5@btinternet.com> - 2013-08-21 02:03 -0700
              Re: size of Tim Rentsch <txr@alumni.caltech.edu> - 2013-08-23 10:27 -0700
                Re: size of Keith Thompson <kst-u@mib.org> - 2013-08-23 10:38 -0700
                Re: size of Tim Rentsch <txr@alumni.caltech.edu> - 2013-08-24 17:25 -0700
              Re: size of Kelsey Bjarnason <kbjarnason@gmail.com> - 2013-08-26 20:20 -0700
            Re: size of gazelle@shell.xmission.com (Kenny McCormack) - 2013-08-21 16:05 +0000
              Re: size of Tim Rentsch <txr@alumni.caltech.edu> - 2013-08-23 10:26 -0700
          Re: size of Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2013-08-21 12:20 -0600
  Re: size of Keith Thompson <kst-u@mib.org> - 2013-08-13 11:50 -0700
    Re: size of Ike Naar <ike@iceland.freeshell.org> - 2013-08-13 21:52 +0000
      Re: size of Keith Thompson <kst-u@mib.org> - 2013-08-13 15:49 -0700
        Re: size of Malcolm McLean <malcolm.mclean5@btinternet.com> - 2013-08-14 08:22 -0700
          Re: size of Keith Thompson <kst-u@mib.org> - 2013-08-14 10:38 -0700
          Re: size of Kelsey Bjarnason <kbjarnason@gmail.com> - 2013-08-14 20:20 +0000
            Re: size of Keith Thompson <kst-u@mib.org> - 2013-08-14 14:57 -0700
            Re: size of Ken Brody <kenbrody@spamcop.net> - 2013-08-15 10:14 -0400
              Re: size of Azazel <azazel@remove.azazel.net> - 2013-08-15 10:11 -0500
                Re: size of Ken Brody <kenbrody@spamcop.net> - 2013-08-16 13:13 -0400
            Re: size of Malcolm McLean <malcolm.mclean5@btinternet.com> - 2013-08-15 08:54 -0700
              Re: size of Kelsey Bjarnason <kbjarnason@gmail.com> - 2013-08-16 16:03 +0000
                Re: size of Malcolm McLean <malcolm.mclean5@btinternet.com> - 2013-08-16 14:36 -0700
                Re: size of James Kuyper <jameskuyper@verizon.net> - 2013-08-16 17:42 -0400
                Re: size of Kelsey Bjarnason <kbjarnason@gmail.com> - 2013-08-17 04:50 +0000
                Re: size of Malcolm McLean <malcolm.mclean5@btinternet.com> - 2013-08-17 03:21 -0700
                Re: size of Stephen Sprunk <stephen@sprunk.org> - 2013-08-17 09:33 -0500
                Re: size of Malcolm McLean <malcolm.mclean5@btinternet.com> - 2013-08-17 07:58 -0700
                Re: size of Ben Bacarisse <ben.usenet@bsb.me.uk> - 2013-08-17 20:17 +0100
                Re: size of Rosario1903 <Rosario@invalid.invalid> - 2013-08-18 09:22 +0200
                Re: size of Stephen Sprunk <stephen@sprunk.org> - 2013-08-19 20:42 -0500
                Re: size of Rosario1903 <Rosario@invalid.invalid> - 2013-08-20 09:03 +0200
                Re: size of Rosario1903 <Rosario@invalid.invalid> - 2013-08-20 09:06 +0200
                Re: size of Ian Collins <ian-news@hotmail.com> - 2013-08-20 20:49 +1200
                Re: size of Rosario1903 <Rosario@invalid.invalid> - 2013-08-20 10:57 +0200
                Re: size of Rosario1903 <Rosario@invalid.invalid> - 2013-08-20 12:40 +0200
                Re: size of Stephen Sprunk <stephen@sprunk.org> - 2013-08-20 07:58 -0500
                Re: size of Rosario1903 <Rosario@invalid.invalid> - 2013-08-20 18:27 +0200
                Re: size of Stephen Sprunk <stephen@sprunk.org> - 2013-08-20 12:27 -0500
                Re: size of Keith Thompson <kst-u@mib.org> - 2013-08-20 12:20 -0700
                Re: size of Ike Naar <ike@iceland.freeshell.org> - 2013-08-20 21:02 +0000
                Re: size of Keith Thompson <kst-u@mib.org> - 2013-08-20 16:10 -0700
                Re: size of Phil Carmody <thefatphil_demunged@yahoo.co.uk> - 2013-08-23 10:50 +0300
                Re: size of Rosario1903 <Rosario@invalid.invalid> - 2013-08-21 07:39 +0200
                Re: size of Stephen Sprunk <stephen@sprunk.org> - 2013-08-22 13:15 -0500
                Re: size of Barry Schwarz <schwarzb@dqel.com> - 2013-08-20 15:17 -0700
                Re: size of Keith Thompson <kst-u@mib.org> - 2013-08-20 16:18 -0700
                Re: size of Stephen Sprunk <stephen@sprunk.org> - 2013-08-20 20:47 -0500
                Re: size of James Kuyper <jameskuyper@verizon.net> - 2013-08-20 23:31 -0400
                Re: size of Stephen Sprunk <stephen@sprunk.org> - 2013-08-20 23:38 -0500
                Re: size of James Kuyper <jameskuyper@verizon.net> - 2013-08-21 07:01 -0400
                Re: size of Stephen Sprunk <stephen@sprunk.org> - 2013-08-22 21:54 -0500
                Re: size of James Kuyper <jameskuyper@verizon.net> - 2013-08-23 00:26 -0400
                Re: size of Stephen Sprunk <stephen@sprunk.org> - 2013-08-24 04:45 -0500
                Re: size of Richard Damon <Richard@Damon-Family.org> - 2013-08-24 08:55 -0400
                Re: size of Stephen Sprunk <stephen@sprunk.org> - 2013-08-24 11:54 -0500
                Re: size of James Kuyper <jameskuyper@verizon.net> - 2013-08-24 13:27 -0400
                Re: size of Robert Wessel <robertwessel2@yahoo.com> - 2013-08-24 14:12 -0500
                Re: size of Richard Damon <Richard@Damon-Family.org> - 2013-08-24 18:01 -0400
                Re: size of glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2013-08-26 01:46 +0000
                Re: size of James Kuyper <jameskuyper@verizon.net> - 2013-08-24 13:23 -0400
                Re: size of Stephen Sprunk <stephen@sprunk.org> - 2013-08-24 14:33 -0500
                Re: size of James Kuyper <jameskuyper@verizon.net> - 2013-08-24 22:47 -0400
                Re: size of Stephen Sprunk <stephen@sprunk.org> - 2013-08-25 04:34 -0500
                Re: size of glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2013-08-26 01:49 +0000
                Re: size of Keith Thompson <kst-u@mib.org> - 2013-08-21 09:04 -0700
                Re: size of Keith Thompson <kst-u@mib.org> - 2013-08-20 23:07 -0700
                Re: size of James Kuyper <jameskuyper@verizon.net> - 2013-08-21 07:06 -0400
                Re: size of Keith Thompson <kst-u@mib.org> - 2013-08-21 09:06 -0700
                Re: size of Keith Thompson <kst-u@mib.org> - 2013-08-20 23:03 -0700
                Re: size of Stephen Sprunk <stephen@sprunk.org> - 2013-08-22 13:34 -0500
                Re: size of James Kuyper <jameskuyper@verizon.net> - 2013-08-22 15:06 -0400
                Re: size of Stephen Sprunk <stephen@sprunk.org> - 2013-08-22 14:42 -0500
                Re: size of Keith Thompson <kst-u@mib.org> - 2013-08-22 12:40 -0700
                Re: size of Keith Thompson <kst-u@mib.org> - 2013-08-22 14:57 -0700
                Re: size of Robert Wessel <robertwessel2@yahoo.com> - 2013-08-22 20:30 -0500
                Re: size of James Kuyper <jameskuyper@verizon.net> - 2013-08-22 22:24 -0400
                Re: size of Stephen Sprunk <stephen@sprunk.org> - 2013-08-22 21:42 -0500
                Re: size of James Kuyper <jameskuyper@verizon.net> - 2013-08-23 00:10 -0400
                Re: size of Stephen Sprunk <stephen@sprunk.org> - 2013-08-22 21:36 -0500
                Re: size of Tim Rentsch <txr@alumni.caltech.edu> - 2013-08-24 14:53 -0700
                Re: size of Keith Thompson <kst-u@mib.org> - 2013-08-22 23:30 -0700
                Re: size of Tim Rentsch <txr@alumni.caltech.edu> - 2013-08-24 10:48 -0700
                Re: size of Stephen Sprunk <stephen@sprunk.org> - 2013-08-24 14:23 -0500
                Re: size of Keith Thompson <kst-u@mib.org> - 2013-08-24 15:42 -0700
                Re: size of Richard Damon <Richard@Damon-Family.org> - 2013-08-24 20:09 -0400
                Re: size of Keith Thompson <kst-u@mib.org> - 2013-08-24 17:52 -0700
                Re: size of James Kuyper <jameskuyper@verizon.net> - 2013-08-24 22:53 -0400
                Re: size of Richard Damon <Richard@Damon-Family.org> - 2013-08-25 08:44 -0400
                Re: size of Tim Rentsch <txr@alumni.caltech.edu> - 2013-08-26 14:27 -0700
                Re: size of Malcolm McLean <malcolm.mclean5@btinternet.com> - 2013-08-26 15:35 -0700
                Re: size of Keith Thompson <kst-u@mib.org> - 2013-08-26 16:08 -0700
                Re: size of Richard Damon <Richard@Damon-Family.org> - 2013-08-26 23:48 -0400
                Re: size of Keith Thompson <kst-u@mib.org> - 2013-08-26 21:50 -0700
                Re: size of Tim Rentsch <txr@alumni.caltech.edu> - 2013-08-25 10:49 -0700
                Re: size of Malcolm McLean <malcolm.mclean5@btinternet.com> - 2013-08-25 11:15 -0700
                Re: size of Keith Thompson <kst-u@mib.org> - 2013-08-24 14:39 -0700
                Re: size of Tim Rentsch <txr@alumni.caltech.edu> - 2013-08-25 18:32 -0700
                Re: size of Keith Thompson <kst-u@mib.org> - 2013-08-25 19:48 -0700
                Re: size of Tim Rentsch <txr@alumni.caltech.edu> - 2013-08-21 00:19 -0700
                Re: size of Stephen Sprunk <stephen@sprunk.org> - 2013-08-20 18:28 -0500
                Re: size of Barry Schwarz <schwarzb@dqel.com> - 2013-08-20 22:02 -0700
                Re: size of Keith Thompson <kst-u@mib.org> - 2013-08-20 23:13 -0700
                Re: size of Tim Rentsch <txr@alumni.caltech.edu> - 2013-08-24 08:48 -0700
                Re: size of Keith Thompson <kst-u@mib.org> - 2013-08-24 14:12 -0700
                Re: size of Tim Rentsch <txr@alumni.caltech.edu> - 2013-08-24 20:35 -0700
                Re: size of Tim Rentsch <txr@alumni.caltech.edu> - 2013-08-24 09:16 -0700
                Re: size of Barry Schwarz <schwarzb@dqel.com> - 2013-08-24 15:14 -0700
                Re: size of Keith Thompson <kst-u@mib.org> - 2013-08-24 15:51 -0700
                Re: size of Tim Rentsch <txr@alumni.caltech.edu> - 2013-08-24 19:39 -0700
                Re: size of Stephen Sprunk <stephen@sprunk.org> - 2013-08-24 11:48 -0500
                Re: size of James Kuyper <jameskuyper@verizon.net> - 2013-08-24 13:36 -0400
                Re: size of Stephen Sprunk <stephen@sprunk.org> - 2013-08-24 14:24 -0500
                Re: size of Barry Schwarz <schwarzb@dqel.com> - 2013-08-24 15:14 -0700
                Re: size of Keith Thompson <kst-u@mib.org> - 2013-08-24 15:46 -0700
                Re: size of Barry Schwarz <schwarzb@dqel.com> - 2013-08-24 21:42 -0700
                Re: size of Keith Thompson <kst-u@mib.org> - 2013-08-25 01:41 -0700
                Re: size of Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2013-08-25 13:46 -0600
                Re: size of Keith Thompson <kst-u@mib.org> - 2013-08-25 13:33 -0700
                Re: size of Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2013-08-25 18:18 -0600
                Re: size of Tim Rentsch <txr@alumni.caltech.edu> - 2013-08-26 18:27 -0700
                Re: size of Keith Thompson <kst-u@mib.org> - 2013-08-26 21:21 -0700
                Re: size of Tim Rentsch <txr@alumni.caltech.edu> - 2013-08-26 18:43 -0700
                Re: size of Richard Damon <Richard@Damon-Family.org> - 2013-08-25 16:52 -0400
                Re: size of James Kuyper <jameskuyper@verizon.net> - 2013-08-25 18:34 -0400
                Re: size of Barry Schwarz <schwarzb@dqel.com> - 2013-08-25 16:20 -0700
                Re: size of James Kuyper <jameskuyper@verizon.net> - 2013-08-25 21:01 -0400
                Re: size of Keith Thompson <kst-u@mib.org> - 2013-08-25 19:33 -0700
                Re: size of Tim Rentsch <txr@alumni.caltech.edu> - 2013-08-26 23:36 -0700
                Re: size of James Kuyper <jameskuyper@verizon.net> - 2013-08-24 23:08 -0400
                Re: size of Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2013-08-25 13:44 -0600
                Re: size of Keith Thompson <kst-u@mib.org> - 2013-08-25 13:31 -0700
                Re: size of Barry Schwarz <schwarzb@dqel.com> - 2013-08-25 16:20 -0700
                Re: size of Richard Damon <Richard@Damon-Family.org> - 2013-08-25 21:48 -0400
                Re: size of Keith Thompson <kst-u@mib.org> - 2013-08-25 19:30 -0700
                Re: size of Ian Collins <ian-news@hotmail.com> - 2013-08-26 14:45 +1200
                Re: size of Keith Thompson <kst-u@mib.org> - 2013-08-25 20:08 -0700
                Re: size of Tim Rentsch <txr@alumni.caltech.edu> - 2013-08-26 18:53 -0700
                Re: size of Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2013-08-26 22:08 -0600
                Re: size of Tim Rentsch <txr@alumni.caltech.edu> - 2013-08-26 23:13 -0700
                Re: size of Tim Rentsch <txr@alumni.caltech.edu> - 2013-08-24 15:08 -0700
                Re: size of Malcolm McLean <malcolm.mclean5@btinternet.com> - 2013-08-24 16:39 -0700
                Re: size of Keith Thompson <kst-u@mib.org> - 2013-08-24 17:48 -0700
                Re: size of Tim Rentsch <txr@alumni.caltech.edu> - 2013-08-24 17:55 -0700
                Re: size of Malcolm McLean <malcolm.mclean5@btinternet.com> - 2013-08-20 01:02 -0700
                Re: size of Ian Collins <ian-news@hotmail.com> - 2013-08-20 20:54 +1200
                Re: size of Kelsey Bjarnason <kbjarnason@gmail.com> - 2013-08-20 02:39 -0700
                Re: size of Stephen Sprunk <stephen@sprunk.org> - 2013-08-20 08:15 -0500
                Re: size of Keith Thompson <kst-u@mib.org> - 2013-08-20 08:17 -0700
                Re: size of Malcolm McLean <malcolm.mclean5@btinternet.com> - 2013-08-20 13:58 -0700
                Re: size of Ike Naar <ike@iceland.freeshell.org> - 2013-08-20 21:11 +0000
                Re: size of gazelle@shell.xmission.com (Kenny McCormack) - 2013-08-20 21:21 +0000
                Re: size of Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2013-08-20 16:21 -0600
                Re: size of gazelle@shell.xmission.com (Kenny McCormack) - 2013-08-21 12:01 +0000
                Re: size of Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2013-08-21 12:11 -0600
                Re: size of gazelle@shell.xmission.com (Kenny McCormack) - 2013-08-22 09:19 +0000
                Re: size of Ian Collins <ian-news@hotmail.com> - 2013-08-21 10:07 +1200
                Re: size of glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2013-08-20 23:58 +0000
                Re: size of Phil Carmody <thefatphil_demunged@yahoo.co.uk> - 2013-08-23 11:24 +0300
                Re: size of glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2013-08-23 10:52 +0000
                Re: size of "James Harris" <james.harris.1@gmail.com> - 2013-08-23 12:09 +0100
                Re: size of Phil Carmody <thefatphil_demunged@yahoo.co.uk> - 2013-08-23 17:52 +0300
                Re: size of Keith Thompson <kst-u@mib.org> - 2013-08-20 16:21 -0700
                Re: size of Malcolm McLean <malcolm.mclean5@btinternet.com> - 2013-08-21 02:23 -0700
                Re: size of glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2013-08-21 10:05 +0000
                Re: size of Malcolm McLean <malcolm.mclean5@btinternet.com> - 2013-08-21 03:23 -0700
                Re: size of Keith Thompson <kst-u@mib.org> - 2013-08-21 08:22 -0700
                Re: size of Ben Bacarisse <ben.usenet@bsb.me.uk> - 2013-08-21 18:54 +0100
                Re: size of Malcolm McLean <malcolm.mclean5@btinternet.com> - 2013-08-21 13:51 -0700
                Re: size of Robert Wessel <robertwessel2@yahoo.com> - 2013-08-21 13:41 -0500
                Re: size of Keith Thompson <kst-u@mib.org> - 2013-08-21 08:42 -0700
                Re: size of Kelsey Bjarnason <kbjarnason@gmail.com> - 2013-08-20 20:44 -0700
                Re: size of Malcolm McLean <malcolm.mclean5@btinternet.com> - 2013-08-21 02:30 -0700
                Re: size of Keith Thompson <kst-u@mib.org> - 2013-08-21 08:30 -0700
                Re: size of Kelsey Bjarnason <kbjarnason@gmail.com> - 2013-08-18 22:15 -0700
                Re: size of Kelsey Bjarnason <kbjarnason@gmail.com> - 2013-08-18 22:08 -0700
        Re: size of Tim Rentsch <txr@alumni.caltech.edu> - 2013-08-18 20:49 -0700
  Re: size of Sjouke Burry <burrynulnulfour@ppllaanneett.nnll> - 2013-08-14 01:09 +0200
    Re: size of Keith Thompson <kst-u@mib.org> - 2013-08-13 17:31 -0700
      Re: size of Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2013-08-13 22:09 -0600
        Re: size of James Kuyper <jameskuyper@verizon.net> - 2013-08-14 07:03 -0400
          Re: size of Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2013-08-14 10:02 -0600
            Re: size of James Kuyper <jameskuyper@verizon.net> - 2013-08-14 12:29 -0400
              Re: size of Stephen Sprunk <stephen@sprunk.org> - 2013-08-14 14:44 -0500
                Re: size of James Kuyper <jameskuyper@verizon.net> - 2013-08-14 16:03 -0400

csiph-web