Re: C++ Bounds Checking
- From: dpb <none@xxxxxxx>
- Date: Fri, 29 Jun 2007 17:30:09 -0500
Wade Ward wrote:
"dpb" <none@xxxxxxx> wrote in message news:f63ib8$vvn$1@xxxxxxxxxxx....dpb wrote:Wade Ward wrote:
...
Most (all?) compilers have compile-time options that can find most instances of uninitialized scalars or character variable references.I tried to search for "unitialized data" in my compiler's manual but got no matches.
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.
Look in the programmers' guide (or whatever they call it) section for compiler switches/flags/options and peruse them. For CVF it looks like--
Undeclared Variables/Symbols /warn:[no]declarations
Uninitialized Variables /warn:[no]uninitialized
These are effective only for scalars, though, not arrays.
CVF doesn't implement the uninitialized variables for arrays, I don't know about any specific compiler.
....again snip code reference uninitialized array element...
!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.
That's one way -- but, what if you're in the main routine and are reading an unknown amount of data yet? Egg and chicken...
As noted, there are lots of ways to handle it. What's most appropriate is dependent on the situation. Automatic arrays and subroutines are another. Simply using an array slice w/ the same variable is quite appropriate and adequate in many cases as well.
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.
Undoubtedly, altho redirection is useful, too... :)
--
.
- Follow-Ups:
- Re: C++ Bounds Checking
- From: Wade Ward
- 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
- Re: C++ Bounds Checking
- From: Wade Ward
- C++ Bounds Checking
- Prev by Date: Re: Need Help: compiling old Fortran program
- Next by Date: Re: fileid=get_lun()
- Previous by thread: Re: C++ Bounds Checking
- Next by thread: Re: C++ Bounds Checking
- Index(es):