Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why would common block variables not preserve their values?

First, I know that using common blocks is a bad idea in fortran (and programming in general). However, I'm updating someone else's code and I don't want to mess up things that are known to work.
Second, I know I should post something more specific then this. If I knew how to reduce this into something small, I would. However, since I know, and I don't think you'll appreciate 2500 lines of code, I can't post a specific example.
With that in mind, I can't describe my problem.

I'm updating someone else's fortran code. The guy used several (4) common blocks to set up global variables. For some reason when I call a function that use such a block, all it's value are 0. Has anyone encountered that before? Does anyone know why this might happen? How to reproduce this? Any starting point to check this would be helpful.

For what it worth, the said common block is declared as

common /set/ block,x,y,z,llx,lly,llz,ilx,ily,ilz,third,third2

block is a 4D array. x, y, and z are 1D array. llx,lly, and llz, are double precision types. The rest are integer types.

The common block(s) is (are) declared and initialized at the main program before any function is called.

like image 840
Yotam Avatar asked Oct 17 '25 06:10

Yotam


1 Answers

Some compilers do initialize common variables to zero, so if you first invoke the function with the common block, you might find zeros everywhere (although you should not rely on that). But once you set some values for the common block variables in the program, those values should appear whenever you use the common block.

As of the variables in the common block: They can be of arbitrary type, as long as they are consistently defined at all places, where the common block is used.

like image 131
Bálint Aradi Avatar answered Oct 19 '25 00:10

Bálint Aradi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!