aliasing error of dummy arguments and common block variables

aliasing error of dummy arguments and common block variables


I am going to make a long fortran main program into a subroutine, what i have done was to arrange some variables (inside the original main fortran program) into the argumenst of that subroutine. However, i got an error "Aliasing of dummy arguments and common block variables". I did some searching on web and found that this error was due to the argument of subroutine is equal to the variables in COMMON BLOCK inside the subroutine.

subroutine abc (var1, var2,var3)


end subroutine abc

It is because the original fortron code is quite long and complicated, I dont want to do a lot of changings inside. Does anyone have idea on how to solve it? Many thanks!!

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

The code you showed is not allowed in Fortran - a variable of a given name cannot be both a dummy argument and in COMMON - you have to pick one or the other.  I am curious, though - the Intel compiler would give you a very different error message for that code and would not mention aliasing. What was the exact text of the error message you saw?

Fortran does have a rule against aliasing. For example, if you did this:

common /cmn/ var1
call sub(var1)
subroutine sub1(arg)
common /cmn/ var1
arg = arg + var1

that would not be allowed because the subroutine is accessing the same data through both the dummy argument and the COMMON block. (Intel Fortran does have a compiler option to allow this aliasing, but it is a bad idea to use it.) This is not what you showed above, though.

Retired 12/31/2016

There are a number of restrictions on subprogram arguments, one of which is

"A common block object must not be one of the following:

  • A dummy argument


The simplest way of converting a program to a subroutine is to give it a subroutine heading with no arguments. After all, most Fortran main programs have no arguments, and those that do take character arguments -- typically from the command line that spawned the program. If you take this approach, you make minimal changes to the source code, but you should not use any of the COMMON blocks from the old subroutine in the newly minted main program.

In the long run, you are better off doing away with all COMMON blocks, replacing some the variables in the blocks by module variables and making subroutine arguments out of the rest.

Leave a Comment

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