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


Groups > comp.lang.c > #43108

Re: size_t, when to use it? (learning)

From Ian Collins <ian-news@hotmail.com>
Newsgroups comp.lang.c
Subject Re: size_t, when to use it? (learning)
Date 2014-04-19 13:04 +1200
Message-ID <bre0cmF43uvU2@mid.individual.net> (permalink)
References (2 earlier) <kfnppkjcqh7.fsf@x-alumni2.alumni.caltech.edu> <adca5e66-f404-485d-8183-d590c404e291@googlegroups.com> <liipst$4h1$1@news.xmission.com> <joq82b-sqg.ln1@wilbur.25thandClement.com> <lisfpv$b20$1@speranza.aioe.org>

Show all headers | View raw


glen herrmannsfeldt wrote:
> william@wilbur.25thandclement.com wrote:
>
> (snip)
>
>> I've fixed several bugs in my career where people used `sizeof (type)',
>> where type was wrong. I've yet to encounter a similar bug where
>> people used `sizeof object'. Anecdotal, but the fact of the
>> matter is that `sizeof object' states more precisely what you
>> want, and precision is important when programming.
>
>> People keep repeating that rule for specific reasons, none of
>> which are to oppress you.
>
> Yes if you sizeof(type) someone could change the type, such that
> it didn't match.
>
> But one could also change the name such that it didn't match.
>
> There might have been:
>
> short *a;
> (... some lines in between)
> a=malloc(100*sizeof(*a));
>
> and someone later changes it to:
>
> short *a;
> long *b;
> (... some lines in between)
> b=malloc(100*sizeof(*a));

The "some lines in between" is one reason for preferring sizeof object, 
especially for a reviewer of the code.

-- 
Ian Collins

Back to comp.lang.c | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

size_t, when to use it? (learning) G G <gdotone@gmail.com> - 2014-04-10 08:11 -0700
  Re: size_t, when to use it? (learning) James Kuyper <jameskuyper@verizon.net> - 2014-04-10 11:42 -0400
    Re: size_t, when to use it? (learning) G G <gdotone@gmail.com> - 2014-04-10 08:53 -0700
  Re: size_t, when to use it? (learning) Kaz Kylheku <kaz@kylheku.com> - 2014-04-10 16:20 +0000
  Re: size_t, when to use it? (learning) Malcolm McLean <malcolm.mclean5@btinternet.com> - 2014-04-10 11:03 -0700
    Re: size_t, when to use it? (learning) Kaz Kylheku <kaz@kylheku.com> - 2014-04-10 18:48 +0000
      Re: size_t, when to use it? (learning) Tim Prince <tprince@computer.org> - 2014-04-10 19:10 -0400
    Re: size_t, when to use it? (learning) glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2014-04-10 20:03 +0000
      Re: size_t, when to use it? (learning) James Kuyper <jameskuyper@verizon.net> - 2014-04-10 16:15 -0400
        Re: size_t, when to use it? (learning) Malcolm McLean <malcolm.mclean5@btinternet.com> - 2014-04-10 13:47 -0700
          Re: size_t, when to use it? (learning) Keith Thompson <kst-u@mib.org> - 2014-04-10 16:27 -0700
          Re: size_t, when to use it? (learning) Malcolm McLean <malcolm.mclean5@btinternet.com> - 2014-04-11 01:08 -0700
            Re: size_t, when to use it? (learning) Ian Collins <ian-news@hotmail.com> - 2014-04-11 20:11 +1200
              Re: size_t, when to use it? (learning) Malcolm McLean <malcolm.mclean5@btinternet.com> - 2014-04-11 05:06 -0700
                Re: size_t, when to use it? (learning) glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2014-04-11 17:40 +0000
            Re: size_t, when to use it? (learning) Tim Rentsch <txr@alumni.caltech.edu> - 2014-04-14 18:44 -0700
          Re: size_t, when to use it? (learning) Ike Naar <ike@iceland.freeshell.org> - 2014-04-11 17:44 +0000
            Re: size_t, when to use it? (learning) Keith Thompson <kst-u@mib.org> - 2014-04-11 12:33 -0700
              Re: size_t, when to use it? (learning) Malcolm McLean <malcolm.mclean5@btinternet.com> - 2014-04-11 13:23 -0700
                Re: size_t, when to use it? (learning) Tim Rentsch <txr@alumni.caltech.edu> - 2014-04-14 18:48 -0700
                Re: size_t, when to use it? (learning) Malcolm McLean <malcolm.mclean5@btinternet.com> - 2014-04-15 00:49 -0700
                Re: size_t, when to use it? (learning) gazelle@shell.xmission.com (Kenny McCormack) - 2014-04-15 08:16 +0000
                Re: size_t, when to use it? (learning) <william@wilbur.25thandClement.com> - 2014-04-18 16:57 -0700
                Re: size_t, when to use it? (learning) glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2014-04-19 00:25 +0000
                Re: size_t, when to use it? (learning) Kaz Kylheku <kaz@kylheku.com> - 2014-04-19 01:03 +0000
                Re: size_t, when to use it? (learning) Ian Collins <ian-news@hotmail.com> - 2014-04-19 13:04 +1200
                Re: size_t, when to use it? (learning) Keith Thompson <kst-u@mib.org> - 2014-04-18 19:23 -0700
                Re: size_t, when to use it? (learning) <william@wilbur.25thandClement.com> - 2014-04-18 19:32 -0700
                Re: size_t, when to use it? (learning) Malcolm McLean <malcolm.mclean5@btinternet.com> - 2014-04-19 03:38 -0700
                Re: size_t, when to use it? (learning) Tim Rentsch <txr@alumni.caltech.edu> - 2014-04-18 09:13 -0700
                Re: size_t, when to use it? (learning) Malcolm McLean <malcolm.mclean5@btinternet.com> - 2014-04-18 14:00 -0700
                Re: size_t, when to use it? (learning) Tim Rentsch <txr@alumni.caltech.edu> - 2014-04-20 16:24 -0700
                Re: size_t, when to use it? (learning) Malcolm McLean <malcolm.mclean5@btinternet.com> - 2014-04-22 03:36 -0700
              Re: size_t, when to use it? (learning) Ike Naar <ike@iceland.freeshell.org> - 2014-04-12 06:53 +0000
            Re: size_t, when to use it? (learning) Martin Shobe <martin.shobe@yahoo.com> - 2014-04-11 14:42 -0500
              Re: size_t, when to use it? (learning) Ike Naar <ike@iceland.freeshell.org> - 2014-04-12 06:55 +0000
    Re: size_t, when to use it? (learning) G G <gdotone@gmail.com> - 2014-04-10 13:42 -0700
      Re: size_t, when to use it? (learning) James Kuyper <jameskuyper@verizon.net> - 2014-04-10 17:07 -0400
        Re: size_t, when to use it? (learning) G G <gdotone@gmail.com> - 2014-04-10 16:11 -0700
      Re: size_t, when to use it? (learning) Malcolm McLean <malcolm.mclean5@btinternet.com> - 2014-04-10 15:08 -0700
        Re: size_t, when to use it? (learning) Keith Thompson <kst-u@mib.org> - 2014-04-10 17:21 -0700
          Re: size_t, when to use it? (learning) gazelle@shell.xmission.com (Kenny McCormack) - 2014-04-11 01:04 +0000
        Re: size_t, when to use it? (learning) Ian Collins <ian-news@hotmail.com> - 2014-04-11 20:06 +1200
    Re: size_t, when to use it? (learning) Tim Rentsch <txr@alumni.caltech.edu> - 2014-04-14 18:33 -0700
    Re: size_t, when to use it? (learning) Rosario193 <Rosario@invalid.invalid> - 2014-04-15 09:37 +0200
  Re: size_t, when to use it? (learning) Ian Collins <ian-news@hotmail.com> - 2014-04-11 20:09 +1200
  Re: size_t, when to use it? (learning) Tim Rentsch <txr@alumni.caltech.edu> - 2014-04-14 18:21 -0700

csiph-web