Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | Ike Naar <ike@iceland.freeshell.org> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: size_t, when to use it? (learning) |
| Date | 2014-04-12 06:53 +0000 |
| Organization | A noiseless patient Spider |
| Message-ID | <slrn3vfslkhoo0.rr8.ike@iceland.freeshell.org> (permalink) |
| References | (2 earlier) <li6ter$m07$1@speranza.aioe.org> <5346FBFF.9070009@verizon.net> <c4d89df1-dcdf-49e9-89f0-c4b4c3c11a4c@googlegroups.com> <slrn3vfslkgagd.rk9.ike@iceland.freeshell.org> <lnzjjr8xuh.fsf@nuthaus.mib.org> |
On 2014-04-11, Keith Thompson <kst-u@mib.org> wrote: > Ike Naar <ike@iceland.freeshell.org> writes: >> On 2014-04-10, Malcolm McLean <malcolm.mclean5@btinternet.com> wrote: >>> Fixed-point numbers are integers to C, but that's just a reflection of the >>> fact that C doesn't have any native syntactical sugar for fixed-point >>> arithmetic. >>> The other question is whether >>> >>> int i; >>> int N = 100000; >>> short *photons = malloc(N * sizeof(short)); >> >> You've tried to allocate space for N pointers-to-short ... > > You've mis-read the code. He's tried to allocate space for N shorts. > >>> for(i=0;i<N;i++) >>> potons[i] = detectphoton(); >> >> ... but here you use the space as if it holds N shorts (assuming >> 'potons' is a typo for 'photons'). >> >> Did you mean >> >> short *photons = malloc(N * sizeof *short); >> >> ? > > No, sizeof *short is a syntax error. > > A better way to write the original would be: > > short *photons = malloc(N * sizeof *photons); > > but the "sizeof(short)" version is correct. Yes I misread the code. Sorry for the confusion.
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll 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