WARN7-Local variables that are referenced before they are set

Top  Previous  Next

 

Local variables that are referenced before they are set (WARN7)

 

This is a list of all local variables that are referenced before they are set. Probably this is an error, because the values of these identifiers are undefined before they are set. An exception is long strings that are not examined, because they are implicitly initialized upon creation.

 

Restrictions:

Variables marked with the absolute directive are not examined. These identifiers shadow another variable in memory, they are changed whenever the other variable changes.

 

Recommendation:

Examine why these variables are referenced before they are set.

 

Example:

 

clip0064

 

Pascal Analyzer also examines local subprograms that are called. Consider this scenario:

 

Example:

 

clip0065

 

This code triggers a warning, because the local variable I is first referenced by InnerProc. The call to InnerProc occurs before I is set in the main body of Proc. Even if I is only referenced when Condition evaluates to True (in InnerProc), this must happen at some occasion, otherwise that check would be pointless.

 

A usual situation which triggers this warning is when an non-initialized variable is passed as a parameter to a function. The function signature declares the parameter as a var-parameter. Changing the parameter to an out-parameter (if possible), avoids this warning.

 

 

See also:

 

Alerts