Echelon Neuron C User Manual
Page 73

Neuron C Programmer’s Guide
61
Example:
network output SNVT_temp nvoTemp;
when (timer_expires(heartbeat))
{
propagate(nvoTemp);
}
The propagate( ) function can also be useful where pointers are used to update
output network variables. For example, assume that some function, f( ),
calculates a complicated set of values and places them in a network variable
structure. Assume the function is designed to operate on several similar such
variables within a device, thus the function is passed a pointer to each variable.
For efficiency, it might be best to code this function to operate on the variables
through a pointer reference. However, the Neuron C compiler cannot distinguish
between a pointer to a regular application variable, and a pointer to a network
variable. Thus, updates to a network variable through a pointer do not trigger an
implicit propagation, and an explicit propagation is required.
Furthermore, because of the inability to distinguish pointers to network
variables, Neuron C treats pointers to network variables as pointers to const
data, thus avoiding the problem of a modification to the variable through the
pointer. In Neuron C, removal of the const attribute is not normally permitted.
However, the #pragma relaxed_casting_on directive directs the compiler to
permit this cast. Casting can either be explicit, or implicit by variable
assignment or function parameter passing.
Example:
network output SNVT_temp_f nvoTemp;
//
// the hypothetical function f() could be supplied with a
// binary (pre-compiled) function library for easy re-use,
// of for protection of intellectual property (function
// f’s algorithm).
//
extern void f(SNVT_temp_f* pNv);
when (some-event)
{
#pragma relaxed_casting_on
// Without pragma above, this would result in
// an error, because the address of a network
// variable is treated as 'const
// Passing such a type as the function parameter
// results in an implicit cast, since the function
// prototype defines the variable as '
f((SNVT_temp_f*)&nvoTemp);
propagate(nvoTemp); // Explicit propagation needed
// because f() modified nvoTemp by pointer.
}