Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | Shao Miller <sha0.miller@gmail.com> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: [MUDFLAP] Is sizeof(ARRAY[0]) equivalent to sizeof(*ARRAY) ? |
| Date | 2013-01-14 17:50 -0500 |
| Organization | A noiseless patient Spider |
| Message-ID | <kd2234$h98$1@dont-email.me> (permalink) |
| References | (11 earlier) <lnfw24d55f.fsf@nuthaus.mib.org> <kcviqf$344$1@dont-email.me> <ln7gngd1jz.fsf@nuthaus.mib.org> <kcvo9s$shm$1@dont-email.me> <kd1sta$9jg$1@speranza.aioe.org> |
On 1/14/2013 16:21, glen herrmannsfeldt wrote:
> Shao Miller <sha0.miller@gmail.com> wrote:
>
> (snip, someone wrote)
>>> Who says the loop is for initialization? It might not even be writing
>>> to the array.
>
>> I did. "The loop body for this could very well initialize ten elements
>> at a time, but I'd probably advance 'i' by 1 instead of by 10, and use
>> the '% 10' operator in the loop's body, if need be." (If you'll forgive
>> the 10 with "operator") I'm saying "if, then", not making a claim about
>> the loop's purpose.
>
> (snip)
>
>> If you are talking about:
>
>> void some_func1(void) {
>> int arr[4];
>> int i;
>>
>> for (i = 0; i < sizeof arr / sizeof arr[0]; i += 10)
>> /* Anything */
>> }
>
>> then I'd certainly say it's silly! We can see right away that the
>> advancement of 'i' is silly! Consider what kind of code review you'd
>> offer someone about this.
>
> OK, how about:
>
> #define N 4
> void some_func1(void) {
> int arr[N];
> int i;
>
> for (i = 0; i < sizeof arr / sizeof arr[0]; i += 10)
> /* Anything */
> }
>
> Depending on how the preprocessor is implemented, the compiler still
> sees 4, but the N could change later.
>
I'm not too sure how to respond to this. :)
Yes, if I read this code, I would ask the programmer why they were
incrementing 'i' by 10, but comparing with 4 in a loop.
Yes, if I recall my experience correctly, GCC with some particular
translation options once emitted an "index out-of-bounds"-style warning
when it looked like the index might index beyond the bounds of the array.
No, I don't think there's anything undefined about the example, other
than the missing statement which has been obviously replaced with a
comment for demonstration purposes.
--
- Shao Miller
--
"Thank you for the kind words; those are the kind of words I like to hear.
Cheerily," -- Richard Harter
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
[MUDFLAP] Is sizeof(ARRAY[0]) equivalent to sizeof(*ARRAY) ? m.labanowicz@gmail.com - 2013-01-09 07:26 -0800
Re: [MUDFLAP] Is sizeof(ARRAY[0]) equivalent to sizeof(*ARRAY) ? James Kuyper <jameskuyper@verizon.net> - 2013-01-09 11:30 -0500
Re: [MUDFLAP] Is sizeof(ARRAY[0]) equivalent to sizeof(*ARRAY) ? Eric Sosman <esosman@comcast-dot-net.invalid> - 2013-01-09 11:58 -0500
Re: [MUDFLAP] Is sizeof(ARRAY[0]) equivalent to sizeof(*ARRAY) ? Robert Wessel <robertwessel2@yahoo.com> - 2013-01-09 12:27 -0600
Re: [MUDFLAP] Is sizeof(ARRAY[0]) equivalent to sizeof(*ARRAY) ? Keith Thompson <kst-u@mib.org> - 2013-01-09 11:22 -0800
Re: [MUDFLAP] Is sizeof(ARRAY[0]) equivalent to sizeof(*ARRAY) ? Shao Miller <sha0.miller@gmail.com> - 2013-01-09 14:39 -0500
Re: [MUDFLAP] Is sizeof(ARRAY[0]) equivalent to sizeof(*ARRAY) ? m.labanowicz@gmail.com - 2013-01-10 02:40 -0800
Re: [MUDFLAP] Is sizeof(ARRAY[0]) equivalent to sizeof(*ARRAY) ? Shao Miller <sha0.miller@gmail.com> - 2013-01-10 08:31 -0500
Re: [MUDFLAP] Is sizeof(ARRAY[0]) equivalent to sizeof(*ARRAY) ? Shao Miller <sha0.miller@gmail.com> - 2013-01-10 08:49 -0500
Re: [MUDFLAP] Is sizeof(ARRAY[0]) equivalent to sizeof(*ARRAY) ? m.labanowicz@gmail.com - 2013-01-10 06:48 -0800
Re: [MUDFLAP] Is sizeof(ARRAY[0]) equivalent to sizeof(*ARRAY) ? Shao Miller <sha0.miller@gmail.com> - 2013-01-10 10:33 -0500
Re: [MUDFLAP] Is sizeof(ARRAY[0]) equivalent to sizeof(*ARRAY) ? Keith Thompson <kst-u@mib.org> - 2013-01-11 08:19 -0800
Re: [MUDFLAP] Is sizeof(ARRAY[0]) equivalent to sizeof(*ARRAY) ? Shao Miller <sha0.miller@gmail.com> - 2013-01-11 12:46 -0500
Re: [MUDFLAP] Is sizeof(ARRAY[0]) equivalent to sizeof(*ARRAY) ? Keith Thompson <kst-u@mib.org> - 2013-01-11 14:04 -0800
Re: [MUDFLAP] Is sizeof(ARRAY[0]) equivalent to sizeof(*ARRAY) ? glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2013-01-11 22:42 +0000
Re: [MUDFLAP] Is sizeof(ARRAY[0]) equivalent to sizeof(*ARRAY) ? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2013-01-12 01:44 +0000
Re: [MUDFLAP] Is sizeof(ARRAY[0]) equivalent to sizeof(*ARRAY) ? Shao Miller <sha0.miller@gmail.com> - 2013-01-11 19:30 -0500
Re: [MUDFLAP] Is sizeof(ARRAY[0]) equivalent to sizeof(*ARRAY) ? Shao Miller <sha0.miller@gmail.com> - 2013-01-11 20:11 -0500
Re: [MUDFLAP] Is sizeof(ARRAY[0]) equivalent to sizeof(*ARRAY) ? glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2013-01-12 01:17 +0000
Re: [MUDFLAP] Is sizeof(ARRAY[0]) equivalent to sizeof(*ARRAY) ? Shao Miller <sha0.miller@gmail.com> - 2013-01-11 20:46 -0500
Re: [MUDFLAP] Is sizeof(ARRAY[0]) equivalent to sizeof(*ARRAY) ? glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2013-01-12 03:14 +0000
Re: [MUDFLAP] Is sizeof(ARRAY[0]) equivalent to sizeof(*ARRAY) ? Keith Thompson <kst-u@mib.org> - 2013-01-12 14:17 -0800
Re: [MUDFLAP] Is sizeof(ARRAY[0]) equivalent to sizeof(*ARRAY) ? Shao Miller <sha0.miller@gmail.com> - 2013-01-12 18:02 -0500
Re: [MUDFLAP] Is sizeof(ARRAY[0]) equivalent to sizeof(*ARRAY) ? Keith Thompson <kst-u@mib.org> - 2013-01-12 15:13 -0800
Re: [MUDFLAP] Is sizeof(ARRAY[0]) equivalent to sizeof(*ARRAY) ? Shao Miller <sha0.miller@gmail.com> - 2013-01-13 16:36 -0500
Re: [MUDFLAP] Is sizeof(ARRAY[0]) equivalent to sizeof(*ARRAY) ? Keith Thompson <kst-u@mib.org> - 2013-01-13 15:39 -0800
Re: [MUDFLAP] Is sizeof(ARRAY[0]) equivalent to sizeof(*ARRAY) ? Shao Miller <sha0.miller@gmail.com> - 2013-01-13 19:17 -0500
Re: [MUDFLAP] Is sizeof(ARRAY[0]) equivalent to sizeof(*ARRAY) ? Keith Thompson <kst-u@mib.org> - 2013-01-13 16:57 -0800
Re: [MUDFLAP] Is sizeof(ARRAY[0]) equivalent to sizeof(*ARRAY) ? Shao Miller <sha0.miller@gmail.com> - 2013-01-13 20:50 -0500
Re: [MUDFLAP] Is sizeof(ARRAY[0]) equivalent to sizeof(*ARRAY) ? Keith Thompson <kst-u@mib.org> - 2013-01-13 19:08 -0800
Re: [MUDFLAP] Is sizeof(ARRAY[0]) equivalent to sizeof(*ARRAY) ? Shao Miller <sha0.miller@gmail.com> - 2013-01-14 00:00 -0500
Re: [MUDFLAP] Is sizeof(ARRAY[0]) equivalent to sizeof(*ARRAY) ? glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2013-01-14 21:21 +0000
Re: [MUDFLAP] Is sizeof(ARRAY[0]) equivalent to sizeof(*ARRAY) ? Shao Miller <sha0.miller@gmail.com> - 2013-01-14 17:50 -0500
Re: [MUDFLAP] Is sizeof(ARRAY[0]) equivalent to sizeof(*ARRAY) ? glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2013-01-14 01:23 +0000
Re: [MUDFLAP] Is sizeof(ARRAY[0]) equivalent to sizeof(*ARRAY) ? Shao Miller <sha0.miller@gmail.com> - 2013-01-13 21:04 -0500
Re: [MUDFLAP] Is sizeof(ARRAY[0]) equivalent to sizeof(*ARRAY) ? Keith Thompson <kst-u@mib.org> - 2013-01-13 19:13 -0800
Re: [MUDFLAP] Is sizeof(ARRAY[0]) equivalent to sizeof(*ARRAY) ? glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2013-01-14 21:37 +0000
Re: [MUDFLAP] Is sizeof(ARRAY[0]) equivalent to sizeof(*ARRAY) ? Keith Thompson <kst-u@mib.org> - 2013-01-11 18:28 -0800
Re: [MUDFLAP] Is sizeof(ARRAY[0]) equivalent to sizeof(*ARRAY) ? Keith Thompson <kst-u@mib.org> - 2013-01-11 18:40 -0800
Re: [MUDFLAP] Is sizeof(ARRAY[0]) equivalent to sizeof(*ARRAY) ? Shao Miller <sha0.miller@gmail.com> - 2013-01-12 04:30 -0500
Re: [MUDFLAP] Is sizeof(ARRAY[0]) equivalent to sizeof(*ARRAY) ? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2013-01-10 14:37 +0000
Re: [MUDFLAP] Is sizeof(ARRAY[0]) equivalent to sizeof(*ARRAY) ? m.labanowicz@gmail.com - 2013-01-10 06:51 -0800
Re: [MUDFLAP] Is sizeof(ARRAY[0]) equivalent to sizeof(*ARRAY) ? m.labanowicz@gmail.com - 2013-01-10 07:41 -0800
Re: [MUDFLAP] Is sizeof(ARRAY[0]) equivalent to sizeof(*ARRAY) ? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2013-01-10 16:55 +0000
Re: [MUDFLAP] Is sizeof(ARRAY[0]) equivalent to sizeof(*ARRAY) ? Shao Miller <sha0.miller@gmail.com> - 2013-01-10 17:41 -0500
Re: [MUDFLAP] Is sizeof(ARRAY[0]) equivalent to sizeof(*ARRAY) ? m.labanowicz@gmail.com - 2013-01-11 03:03 -0800
Re: [MUDFLAP] Is sizeof(ARRAY[0]) equivalent to sizeof(*ARRAY) ? m.labanowicz@gmail.com - 2013-01-11 04:14 -0800
Re: [MUDFLAP] Is sizeof(ARRAY[0]) equivalent to sizeof(*ARRAY) ? James Kuyper <jameskuyper@verizon.net> - 2013-01-11 08:32 -0500
csiph-web