aliasing error of dummy arguments and common block variables

aliasing error of dummy arguments and common block variables

Hi,

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)

COMMON/par1/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 post / 0 nuovi
Ultimo contenuto
Per informazioni complete sulle ottimizzazioni del compilatore, consultare l'Avviso sull'ottimizzazione
Ritratto di Steve Lionel (Intel)

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.

Steve
Ritratto di mecej4

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.

Accedere per lasciare un commento.