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

Check for uninitilaized variables useless if using FORALL construct

Intel_C_Intel
Employee
602 Views

The following code illustrates this. The index of every FORALL construct is always flagged as an unititialized variable if you ask for this check.

integer(4) a(12)
forall (i=1:12) a(i)=0
end

Message Edited by VanEck on 08-26-2005 12:44 PM

0 Kudos
4 Replies
Steven_L_Intel1
Employee
602 Views
Yep - this got reported to us the other day. It's being fixed.
0 Kudos
Intel_C_Intel
Employee
602 Views

Please, have a look at the abstract from ISO Fortran 2003 Draft. Does it mean that index-name variable in, for example, forall construct may not be declared? I mean, for code like: forall( i = 1, 10) A(i) = 5 declaration: integer i is unnecessary? Examples in standard say the same. If yes, what about Fortran 95 standard? Any explanation will be appreciated.

16.3 Statement and construct entities

A variable that appears as a data-i-do-variable in a DATA statement or an ac-do-variable in an array constructor, as a dummy argument in a statement function statement, or as an index-name in a FORALL statement is a statement entity. A variable that appears as an index-name in a FORALL construct or an associate-name in a SELECT TYPE or ASSOCIATE construct is a construct entity.

The name of a data-i-do-variable in a DATA statement or an ac-do-variable in an array constructor has a scope of its data-implied-do or ac-implied-do. It is a scalar variable that has the type and type parameters that it would have if it were the name of a variable in the scoping unit that includes the DATA statement or array constructor, and this type shall be integer type; it has no other attributes. The appearance of a name as a data-i-do-variable of an implied-DO in a DATA statement or an ac-dovariable in an array constructor is not an implicit declaration of a variable whose scope is the scoping unit that contains the statement.

The name of a variable that appears as an index-name in a FORALL statement or FORALL construct has a scope of the statement or construct. It is a scalar variable that has the type and type parameters that it would have if it were the name of a variable in the scoping unit that includes the FORALL, and this type shall be integer type; it has no other attributes. The appearance of a name as an index-name in a FORALL statement or FORALL construct is not an implicit declaration of a variable whose scope is the scoping unit that contains the statement or construct.

The name of a variable that appears as a dummy argument in a statement function statement has a scope of the statement in which it appears. It is a scalar that has the type and type parameters that it would have if it were the name of a variable in the scoping unit that includes the statement function; it has no other attributes.

Except for a common block name or a scalar variable name, a global identifier or a local identifier of class (1) (16.2) in the scoping unit that contains a statement shall not be the name of a statement entity of that statement. Within the scope of a statement entity, another statement entity shall not have the same name.

If a global or local identifier accessible in the scoping unit of a statement is the same as the name of a statement entity in that statement, the name is interpreted within the scope of the statement entity as that of the statement entity. Elsewhere in the scoping unit, including parts of the statement outside the scope of the statement entity, the name is interpreted as the global or local identifier.

Except for a common block name or a scalar variable name, a global identifier or a local identifier of class (1) (16.2) in the scoping unit of a FORALL statement or FORALL construct shall not be the same as any of its index-names. An index-name of a contained FORALL statement or FORALL construct shall not be the same as an index-name of any of its containing FORALL constructs.

If a global or local identifier accessible in the scoping unit of a FORALL statement or FORALL construct is the same as the index-name, the name is interpreted within the scope of the FORALL statement or FORALL construct as that of the index-name. Elsewhere in the scoping unit, the name is interpreted as the global or local identifier.

The associate name of a SELECT TYPE construct has a separate scope for each block of the construct. Within each block, it has the declared type, dynamic type, type parameters, rank, and bounds specified in 8.1.5.2.

The associate names of an ASSOCIATE construct have the scope of the block. They have the declared type, dynamic type, type parameters, rank, and bounds specified in 8.1.4.2.

If a global or local identifier accessible in the scoping unit of a SELECT TYPE or ASSOCIATE construct is the same as an associate name, the name is interpreted within the blocks of the SELECT TYPE or ASSOCIATE construct as that of the associate name. Elsewhere in the scoping unit, the name is interpreted as the global or local identifier.

0 Kudos
Steven_L_Intel1
Employee
602 Views
Stanislav,

Please understand that this thread was discussing a run-time warning that a variable was uninitialized - not that it was undeclared.

FORALL variables can be declared - at least given a type. But, as the text you quoted says, the FORALL index variable is not the variable in the routine scope, it is another variable of the same name and type with scope inside the FORALL only. Implied-DO control variables are similar.

If you had IMPLICIT NONE in effect, then you would have to declare a FORALL index variable. If you named it X or B, something that is implicitly REAL, then you would have to declare it with INTEGER type. But it is just the type that is taken from the declaration.
0 Kudos
Intel_C_Intel
Employee
602 Views
Thank you very much, Steve. As always youdot one's "i's" and cross one's "t's".
0 Kudos
Reply