Next: , Previous: , Up: preprocessor   [Contents][Index]


2.7 Variable name references

The preprocessor implements facilities to declare variables with unique names and use them as target for variables with the NAMEREF attribute. With these facilities we can use the _var variants of MBFL functions as follows:

mbfl_local_varref(RV)

mbfl_file_extension_var mbfl_datavar(RV) /path/to/file.ext
"$RV"  ⇒ ext

without risking a variable name collision. In this example, the use of mbfl_local_varref() expands into:

local mbfl_a_variable_RV
mbfl_variable_alloc mbfl_a_variable_RV
local $mbfl_a_variable_RV
local -n RV=$mbfl_a_variable_RV

a local name variable mbfl_a_variable_RV is declared and filled with a unique data variable name by mbfl_variable_alloc(); then the data variable is declared as local; finally a proxy variable RV is defined as alias for the data variable.

Given a proxy variable name defined this way: we can retrieve its name variable name with the macro mbfl_namevar(); we can retrieve its data variable name with the macro mbfl_datavar().

Other macros declare variables similarly, using the same scheme of 3 variable declarations: name variable, data variable, proxy variable.


Next: , Previous: , Up: preprocessor   [Contents][Index]

This document describes version 3.0.0-devel.0 of Marcos Bash Functions Library.