global

Define global scope or make a local variable global.

Syntax

status = global ( [ variable ] ) ;

Arguments

list variable (optional)

Return Value

str status

Exceptions

%ARGUMENT : Invalid arguments. Usage: status = global ( [ variable ] ) ;

%IDENTIFIER : 'variable' argument is not a valid identifier, literal, or reference

%UNDEFINED : Variable does not exist

Description

In global scope, variables defined will be global in scope.

In local scope, variables defined will be local in scope.

If a variable is local, it can be redefined in global scope. Any previous global variable is overwritten and the local definition no longer exists.

If a variable is global, it can be redefined in local scope. Any previous local variable is overwritten and the global definition no longer exists.

Global variables (and methods) created by the concept instance have a super-global scope, they are visible to all instances providing the instance has not already defined the variable in local or global scope. If the instance un-defines its own global and local copies of the variable, then the variable defined in the concept instance becomes visible. Local variables created in the concept instance are not accessible by other instances and visa versa.

A common mistake when trying to create a local variable over top of a global variable is not to typedef it. For example:

	
	// Define global scope
	global ;
	
	// Define a global variable (we didn't use a typedef, so the type is 'list'
	a = 100 ;
	// Define local scope
	local ;
	// The following statement simply overwrites the global variable 'a'
	a = 101 ;
	// But the next statement creates a new local variable because it was typedef'd
	int a = 1 ;

Examples

To execute the example below, press or modify the example to try different variations.

Related Links

local