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


Groups > comp.lang.c > #42781

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

From James Kuyper <jameskuyper@verizon.net>
Newsgroups comp.lang.c
Subject Re: size_t, when to use it? (learning)
Date 2014-04-10 16:15 -0400
Organization Self
Message-ID <5346FBFF.9070009@verizon.net> (permalink)
References <8fcc0c7e-0add-4607-ab04-2bbe5e0a7bfe@googlegroups.com> <f0d38a56-5b46-42b6-8762-ad0e683b2723@googlegroups.com> <li6ter$m07$1@speranza.aioe.org>

Show all headers | View raw


On 04/10/2014 04:03 PM, glen herrmannsfeldt wrote:
> Malcolm McLean <malcolm.mclean5@btinternet.com> wrote:
...
>> Firstly, if sizes in bytes, counts of objects, index variables, 
>> and intermediate variables used in calculating indices are all 
>> size_t, then that's practically all the integers in a typical C 
>> program.

Most of the integers in my programs contain either unsigned 12-bit
photon counts (the relevant photons could be considered objects in some
sense, but they are not C objects), or signed 16-bit scaled integers,
neither of which fits into any of the categories you've listed. These
often occur in fairly large (multi-million element) arrays, so using a
32-bit int to store them would be pretty wasteful.

...
>> My own view is, don't use size_t at all. Just pass ints to 
>> the standard library functions and pretend it was never invented. 
> 
> When you know that int will always be big enough, that seems right
> to me. 

Having frequently programmed on systems where int had 16 bits, I learned
pretty quickly not to make such assumptions.

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