Re: C++ Bounds Checking
- From: "Wade Ward" <invalid@xxxxxxxxxxxx>
- Date: Fri, 29 Jun 2007 18:13:02 -0400
"dpb" <none@xxxxxxx> wrote in message news:f63ib8$vvn$1@xxxxxxxxxxx
dpb wrote:I tried to search for "unitialized data" in my compiler's manual but got no
Wade Ward wrote:...
...
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.
Actually, of course, what the uninitialized array entry would be would be
immaterial to whether SUM() was or wasn't called, of course... :)
I was going to add that what you're seemingly looking for here is
"uninitialized data" usage, not bounds checking.
Most (all?) compilers have compile-time options that can find most
instances of uninitialized scalars or character variable references.
Some I believe have options that set all(?) data to unique bit patterns
that allows for runtime checking of uninitialized data similar to bounds
checking runtime code.
matches.
program sum1
implicit none
integer, dimension(85) :: age
integer :: i,sigma
open (13,File="output2.txt", status='replace')
do i=1, 84
age(i)=i
end do
sigma = sum(age)
write (13, '(a)', advance= 'no') "The sum is "
write (13,*) sigma
! same control, different upper bound
do i=1, 85
age(i)=i
end do
sigma = sum(age)
write (13, '(a)', advance= 'no') "The sum is "
write (13,*) sigma
close (13)
end program sum1
!end source begin output
The sum is -2139058574
The sum is 3655
That 85th one is clearly a whopper. Maybe the best way to deal with this is
to make an array allocatable, so that the same variable that defines its
size can be used as the bound for loops. It sure is nice to know how to
write output to text files as opposed to doing the gymnastics of redirecting
output with a dos prompt.
--
WW
.
- Follow-Ups:
- 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
- Re: C++ Bounds Checking
- From: dpb
- C++ Bounds Checking
- Prev by Date: Re: C++ Bounds Checking
- Next by Date: Re: Need Help: compiling old Fortran program
- Previous by thread: Re: C++ Bounds Checking
- Next by thread: Re: C++ Bounds Checking
- Index(es):
Relevant Pages
|