"execute ok, debug crash" help

"execute ok, debug crash" help

A friend of mine come across this problem when he used CVF 6.5.

He had a program that compiles, runs and debugs ok in CVF 6.5

Then he changed almost all the arrays in the program from static to dynamic (allocate at runtime). after that, the program compiles and runs (executes) ok in CVF 6.5. But if he debug it (Go...), it will crash during the process at some point with impossible errors:

Sqrt(a^2+b^2)...

Error: a^2+b^2 becomes negative, So sqrt(negative number) --> crash

Any one has an idea ? any help is highly appreciated.

Thanks

8 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

Allocated arrays are not zero-initialized like static arrays in CVF; they contain random garbage (which will be different under Debug and Release). Presumably that is the cause of the behaviour...somewhere. My guess is that a**2 + b**2 is not negative, but contains a NaN.

Jugoslav

Jugoslav
www.xeffort.com

Static arrays aren't zero-initialized either - at least they're not guaranteed to be. Don't assume any initialization you didn't do yourself.

Steve

Steve - Intel Developer Support

However, Steve, I think that CVF's extension with zero-initialization of static variables is actually a disservice to users. It encourages bad coding practices. I'd far prefer to have a predefined-garbage-initialization in debug mode, and "whatever was there" in release mode. I realize that default-zero initialization is necessary for old dirty codes, but that should be solved by a compiler switch. (AFAIK now we don't even have a compiler switch for not initializing statics to zero, except not-so-reliable "Variables default to automatic"). Can it be expected in VF7?

Btw, I noticed that ALLOCATEd memory is initialized with 0xCDCDCDCD under debugger at my 6.6/Win2K/Athlon. Do you maybe know where that value comes from? RTL, debugger or something else?

Jugoslav

Jugoslav
www.xeffort.com

CVF has no such extension - the compiler does not lift a finger to cause variables to be zero-initialized by default. You get whatever the linker and image activator give you. By default, the variables are in a type of image section that has no initialization whatsoever. It just so happens that, most of the time, these end up as zero, but you can't count on it.

The only platform on which Compaq Fortran compilers explicitly zero initialize static variables is OpenVMS.

If you want to have fun, compile with "Variables default to AUTOMATIC" - then you'll definitely have a lot of non-zero values in your uninitialized variables.

Steve

Steve - Intel Developer Support

Sorry, I stand corrected; I thought I had read it somewhere, but that apparently weren't CVF docs :-).

Still, are there any plans for including run-time checks of variables initialization? Compile-time checks are inherently insufficient. I had a hard time recently trying to locate a bug caused by access to a non-initialized member of an allocated array; the crash occurred only under profiler (sigh).

Jugoslav

Jugoslav
www.xeffort.com

Yes, I just initialized the variables and problem solved.

Thank you all very much.

Fanqingfuming

You cannot take the square root of a negative number. There is no number that when multiplied by itself equals a negative number.

One way to get around the problem is an IF then check around the A^2+B^2. If the result is positive then perform the square root, else zero.

Leave a Comment

Please sign in to add a comment. Not a member? Join today