Re: C++ Bounds Checking
- From: "Wade Ward" <invalid@xxxxxxxxxxxx>
- Date: Fri, 29 Jun 2007 16:17:23 -0400
"dpb" <none@xxxxxxx> wrote in message news:f632dr$56g$1@xxxxxxxxxxx
Wade Ward wrote:So bounds checking is going to issue a diagnostic if I want to assign to say
...
How the heck are you supposed to get a compiler to get bounds right when...snip code example of using only subset of an array...
programmers can't? In this source:
, I think I got the right answer by grace. If instead, I had used the
intrinsic sum, what would that 85th integer be?
Depends on what you passed SUM() as the argument.
You're missing the point of bounds checking methinks. Bounds checking
finds cases where the array is addressed _outside_ of the defined bounds
of the array itself. In your example of an array of size 85, an attempt
to address age(i) w/ i<1 or i>85 would trigger an error if bounds checking
was in effect, otherwise the code would either silently address memory
outside of the array (if it happened it was addressable space for your
process) or _perhaps_ abort if it happened to be in system-protected
memory. This is the classic "buffer overrun" problem.
Knowing that you have only used 84 of the 85 possible array entries is,
indeed, your responsibility as programmer to ensure the code logic is
written to "know" conditions such as that and handle them properly.
There are as many ways to do this as there are programmers, probably. A
couple of obvious ways in your case would be to put the computation(s)
using the array after it is filled w/ data in a subroutine and pass the
elements that are used only so the subroutine has a full array. Or, an
array slice could be passed to the SUM() intrinsic or the optional MASK
argument could have been used if the array had been initialized to a
specific value (something <0) would have been a good choice here as ages
presumably aren't negative).
array(-1) or array(90) given that I have an 85-dimensional entity. Indeed,
I tried to use the intrinsic sum but got a buffer overflow at runtime. I
try to familiarize myself with the intrinsics as I go. It just seems like a
tall order to ask a compiler to know what's going to happen at runtime.
--
WW
.
- Follow-Ups:
- Re: C++ Bounds Checking
- From: Gordon Sande
- Re: C++ Bounds Checking
- From: dpb
- Re: C++ Bounds Checking
- References:
- C++ Bounds Checking
- From: Gary Scott
- Re: C++ Bounds Checking
- From: Gary Scott
- Re: C++ Bounds Checking
- From: Wade Ward
- Re: C++ Bounds Checking
- From: dpb
- C++ Bounds Checking
- Prev by Date: Re: Need Help: compiling old Fortran program
- Next by Date: Re: Form k = i + j and test for overflow.
- Previous by thread: Re: C++ Bounds Checking
- Next by thread: Re: C++ Bounds Checking
- Index(es):
Relevant Pages
|