Re: C++ Bounds Checking




"dpb" <none@xxxxxxx> wrote in message news:f63ib8$vvn$1@xxxxxxxxxxx
dpb wrote:
Wade Ward wrote:
...
How the heck are you supposed to get a compiler to get bounds right when
programmers can't? In this source:

...snip code example of using only subset of an array...

, 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.
I tried to search for "unitialized data" in my compiler's manual but got no
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


.



Relevant Pages

  • an integral expression for the sum of divisors function
    ... analytic function. ... expression for the sum of divisors function that I discovered. ... Here we have a multiple integral expression for sigma ...
    (sci.math)
  • Re: Gaussian Noise Generation
    ... You need to sum up some (finite variance) IID samples before ... sigma * sqrt ...
    (comp.dsp)
  • Re: Gaussian Noise Generation
    ... You need to sum up some (finite variance) IID samples before ... sigma * sqrt ...
    (comp.dsp)
  • Re: about return values
    ... I made a simple shell script like this below in ksh. ... ((sum = sum + yo)) ... sigma 100 ... is to return exit status codes (error codes), ...
    (comp.unix.shell)
  • Re: C++ Bounds Checking
    ... Depends on what you passed SUM() as the argument. ... Most compilers have compile-time options that can find most instances of uninitialized scalars or character variable references. ... Some I believe have options that set alldata to unique bit patterns that allows for runtime checking of uninitialized data similar to bounds checking runtime code. ...
    (comp.lang.fortran)