Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | Keith Thompson <kst-u@mib.org> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: [MUDFLAP] Is sizeof(ARRAY[0]) equivalent to sizeof(*ARRAY) ? |
| Date | 2013-01-12 14:17 -0800 |
| Organization | None to speak of |
| Message-ID | <lnobguhwql.fsf@nuthaus.mib.org> (permalink) |
| References | (4 earlier) <kcpj52$lv9$1@dont-email.me> <lntxqnjs1a.fsf@nuthaus.mib.org> <kcqar7$asb$1@dont-email.me> <kcqdj4$7ip$1@speranza.aioe.org> <kcqfa7$vb7$1@dont-email.me> |
Shao Miller <sha0.miller@gmail.com> writes:
> On 1/11/2013 20:17, glen herrmannsfeldt wrote:
>> Shao Miller <sha0.miller@gmail.com> wrote:
[...]
>>> But that's not so. A compiler can plainly see an integer object being
>>> compared with the bounds of an array, as does the code I was
>>> criticizing. For example:
>>
>>> for (i = 0; i < sizeof arr / sizeof arr[0]; i += 10)
>>
>>> If the count of 'arr' is 4, this alone is sufficient cause to tell the
>>> programmer to have their head checked, with no pointers in sight.
>>
>> (And I presume referencing arr[i] inside the loop.)
>
> No, that was the point. There is no 'arr[i]' in the loop and yet the
> compiler (or run-time support, perhaps) can still see that something
> doesn't seem quite right about this. Why is 'i' being incremented by
> 10 and then compared against the length of 'arr'? Seems fishy.
The point of the check is precisely to prevent any invalid access to the
array. Warning about it would make as much sense as this:
int x, y, z;
/* code to set x, y, and z */
if (y == 0) {
z = 0;
}
else {
z = x / y;
}
triggering a warning about a possible division by zero.
--
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 | 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