Global variable might not have been initialized

Navigation:  Messages > Macro Compiler Messages > Warnings >

Global variable might not have been initialized

Previous pageReturn to chapter overviewNext page

This compiler warning means that, at the line where it occurs, the value of a global variable is used that may not have been initialized. For example :

 

global

   nCounter

var

begin

   nCounter = nCounter + 1

end

 

To address the conditions that lead to this warning, makse sure that any path of execution through your macro either assigns a value to the global variable, or verifies successfully that it was initialized previously. Below is a sniplet that does this :

 

if IsInitialized(nCounter)

 // successfull call branch

 // do whatever you want, nCounter is already initialized

else

 // un-successfull call branch

 // but we assign a value to nCounter, so NO warning

 nCounter = 0

endif  

nCounter = nCounter + 1

 

The difference between this message about global variables and the corresponding message for normal variables is that for global variables, the compiler checks that either the variable was assigned a value before reaching a particular line of code, or that a successful call to the function IsInitialized guarantees that the global variable was initialized in a previous iteration of the macro.

 

This message can also occur when your code has a branch before a line that refers to a global variable.

 

global

   nCounter

var

   bIsFirstPage

begin

  if n_OutputPage mod 2 == 0

       bIsFirstPage = IsInitialized(nCounter)

  endif  

   nCounter = nCounter + 1

end

 

See also : Variable is not initialized.


Topic 109026 updated on 01-Nov-2016.
Topic URL: http://www.qppstudio.net/webhelp/index.html?globalvariablemightnothave.htm