Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29249 Discussions

the writing of a variable changes (other) variables addresses

poopants
Beginner
831 Views

hello,

I'm wrote a program, half a year ago. It worked perfectly. Now a collegue tried to run it, but she got some really bogus results ... so I started debugging.

The problem is like this:

I have an integer and a float array. When I write the integer before and after, my nested do-loops for filling my float array, ... I get different results

It seems that the address of my integer is the same as the address of 1 element of my array. So ... with the filling of my array, my integer gets overwritten and ....

Nowhere in the program is there any usage of pointers, so I couldn't accidently change addresses ...

Now for the weirdest thing ...

when I add an extra write(*,*) of one completly different variable, between the write of the int AND the filling of the array ...

magic happens, and everything works as was intended.

Anyone can help me with this ? This type of problem( getting bogus data, which can be solved by adding some nonsense write(*,*) 's, ), I have encountered now, for the third time ... Do I miss something important/obvious ?

Thanks in advance

Jo

0 Kudos
3 Replies
Steven_L_Intel1
Employee
831 Views
The program has a bug in it - you just hid it by adding the write that caused data to be allocated in different places. It is still overwriting memory, just some place you have not noticed.

Turn on bounds checking (-CB) and verify that when you pass arguments the types match. Try compiling with "-gen_interfaces -warn interfaces" and see if it tells you anything.
0 Kudos
poopants
Beginner
831 Views

Steve,

Thank you for yourquick reply.

The -CB optionindeed pointed out where we went out of bounds. We corrected our bug accordingly.

Thank you very much !!!!!

0 Kudos
Steven_L_Intel1
Employee
831 Views
You're welcome. You may want to think about what this means for the past results from this program...
0 Kudos
Reply