References to Variables

Prev Next

Introduction

In several cases, sophisticated variable structures with multiple levels, e.g. a[b,c,d,e] need to be referenced repeatedly where every reference checks for the existence of of the base variable name and all names a through e. To address this problem, B4P provides the feature called refrences to variables which allows you to define variables which poinnt to other base variables, regardless if they are base variables, intermediate or leaf members inside variable structures.

References to variables in B4P have similarities with references in other modern programming languges such as C++, C# and Java. References are not pointers, i.e. any for of mingling up pointers with pointer arithmetics is not supported here.

Destination variables which are pointed by references carry along a kind of blocking notice which forbids deleting them until all references applied on them have been released again. This protection mechanism avoids working with disconnected references pointing to nowhere. Automatic releases will happen with locally defined references to variables in program, procedure and function blocks when leaving. The remaining references will be released in a coordinated manner when the program ends execution.

References in Function Parameters

Some B4P functions and user-defined functions can accept parameters as references to variables, too. These parameters provide access to the base variable as well as to all mebmer variables.