Fortran Compiler Terminology: Dummy Variables and Attributes

Can someone explain to me which abstraction in the parser / compiler corresponds to a dummy variable or attribute?

PURE SUBROUTINE F(X, Y) IMPLICIT NONE REAL, INTENT(INOUT) :: X, Y, C C REAL :: A, B C REAL, SAVE :: C = 3.14E0 PARAMETER (C = 3.14E0, X = 32, Y = X) X = Y + 2 * SIN(Y) END 

 cetin@unique :~/lab/secret/tapenade$ gfortran -x f77 -c 1.f 1.f:6.37: PARAMETER (C = 3.14E0, X = 32, Y = X) 1 Error: PARAMETER attribute conflicts with DUMMY attribute in 'x' at (1) 1.f:3.38: REAL, INTENT(INOUT) :: X, Y, C 1 Error: Symbol at (1) is not a DUMMY variable 

 cetin@unique :~/lab/secret/tapenade$ ifort -c 1.f 1.f(3): error #6451: A dummy argument name is required in this context. [C] REAL, INTENT(INOUT) :: X, Y, C -------------------------------------^ 1.f(6): error #6406: Conflicting attributes or multiple declaration of name. [X] PARAMETER (C = 3.14E0, X = 32, Y = X) -------------------------------^ 1.f(6): error #6406: Conflicting attributes or multiple declaration of name. [Y] PARAMETER (C = 3.14E0, X = 32, Y = X) ---------------------------------------^ 1.f(6): error #6592: This symbol must be a defined parameter, an enumerator, or an argument of an inquiry function that evaluates to a compile-time constant. [X] PARAMETER (C = 3.14E0, X = 32, Y = X) -------------------------------------------^ compilation aborted for 1.f (code 1) 
+6
variables fortran attributes
source share
2 answers

Fortran follows the link. The dummy attribute corresponds to those variables that are passed to the function ( X and Y in your case). The parameter operator expects something static, but since X is what is passed to the function, it really makes no sense. A parameter operator is a way of setting constants - it has nothing to do with subroutine parameters.

When you receive an error message that C not a DUMMY variable, it means that it does not find C in the list of variables that will be transferred to / from the function - your declaration is only F(X, Y) : no C in sight . Although you are not explicitly using the DUMMY attribute, you have the INTENT(INOUT) attribute, which means that these variables correspond to the I / O of the subroutine.

To get what you want, you will have a routine that looks something like this:

 subroutine F(X, Y) implicit none ! These are the dummy variables real, intent(inout) :: X, Y ! These are the variables in the scope of this subroutine real :: a, b real, parameter, save :: c = 3.14E0 X = Y + 2*sin(Y) end subroutine F 

I'm not quite sure what you are trying to do - you are declaring a pure routine, which means a routine without side effects, but you are using INTENT(INOUT) for your variables, which means that X and Y can be changed at runtime.

I would also add that inside a subroutine, initializing a variable in its statement of an expression of type REAL :: C = 3.14E0 gives a variable with the implicit save attribute. If you want it to be saved from call to call, you did the right thing by explicitly adding the save attribute so that it is clear that this is what you are doing.

I am not a parser and compiler guy, but I think that to answer your question the DUMMY attribute means that you just get a pointer - you do not need to allocate any space, since the variable used in the function call already has allocated space.

+9
source share

The real challenge with the call is well explained by Tim Whitcomb. I will try to explain the terms in more detail.

A dummy argument is a special term in Fortran. This is what other languages ​​call formal parameters or similar, that is, it is an object called X and Y (in your case), and witch gets bound to the actual argument when the procedure is called.

Therefore, in:

 subroutine s(i) integer :: i end call s(1) 

i is the dummy argument of subroutine s , and expression 1 is the actual argument that is passed to the subroutine in dummy argument i .

Attributes are a form of indicating additional properties of objects or data procedures. Attributes can be specified using operators:

 real c intent(in) c optional c 

or they can be indicated in one ad:

 real, intent(in), optional :: c 

Thus, the dummy argument c is real by default with the intent(in) and optional attributes.

Conflicting attributes are attributes that cannot be specified for one object at a time. Your example with intent(...) and parameter serves well. They are incompatible, because the first implies a dummy argument, and the other indicates a named constant.

+3
source share

All Articles