Reference Talk:Declare and Local Directives
Jump to navigation
Jump to search
preserving some deleted markup:
New in version 3.7.1: To circumvent the pitfalls of identifier name collisions, two pseudo-functions are provided to specifically refer to identifiers at either the global or the most local scope:
IDENTIFIER: GLOBAL_IDENTIFIER | LOCAL_IDENTIFIER | GENERIC_IDENTIFIER GLOBAL_IDENTIFIER: global ( GENERIC_IDENTIFIER ) LOCAL_IDENTIFIER: local ( GENERIC_IDENTIFIER )
Both pseudo-functions can be used anywhere an identifier is allowed. They do not simply retrieve the cooresponding value, but refer to the identifiers themselves, allowing for constructs like the following:
#ifdef(local(Foo)) #declare global(Foo) = Foo; #else #undef global(Foo) #end
This example tests whether the identifier Foo
is in use
at the most local scope, and if so, copies its value to the global variable
of the same name; otherwise, it discards any value the global variable may
have held before.