uCalc API Version: 5.7.0-preview.1 Released: 7/30/2026

Warning

uCalc API Preview Release Notice:This preview documentation describes the intended behavior of the API. It is not fully accurate or complete.The current preview build contains incomplete features, unoptimized performance, and is subject to breaking changes.Use of the preview version in your production code is not recommended.

FunctionAddress = [OpCallback]

Property

Product: 

Class: 

Gets or sets the memory address of a native callback function associated with a uCalc symbol, enabling implementation sharing and runtime hot-swapping.

Remarks

🔗 FunctionAddress Property

The FunctionAddress property gets or sets the memory address of the native callback function associated with a uCalc Item. This provides a powerful link between a symbol defined in the uCalc engine (like a function or operator) and a function in the host application's native code (C#, C++, VB).

It is a key feature for advanced scenarios involving dynamic behavior, performance optimization, and code reuse.


📖 Getter: Reusing Implementations

When used as a getter, FunctionAddress retrieves the address of the native callback implementing a function's logic.

var floorAddr = uc.ItemOf("Floor").FunctionAddress;

The most common use case is to create a new function or operator that reuses the logic of an existing native-bound function. This allows you to define a new symbol with a different name or properties while pointing it to the same high-performance native code.

FunctionAddress vs. CreateAlias

It is crucial to understand the difference between sharing a function address and creating an alias with CreateAlias.

  • CreateAlias("New", "Old"): Creates a new name that points to the exact same Item. It is a simple synonym.
  • Using FunctionAddress: You can have a completely new and independent Item that just happens to point to the same native callback address. This new item can have its own distinct properties.

✍️ Setter: Hot-Swapping Implementations

When used as a setter, FunctionAddress provides a powerful mechanism to hot-swap the native code implementation of an Item at runtime.

uc.ItemOf("MyRound").FunctionAddress = ceilAddr;

This decouples a symbol's name from its concrete implementation, enabling advanced dynamic behaviors:

  • Dynamic Aliasing: Redirect one function to another. The practical example demonstrates making a custom MyRound function point first to Floor and then to Ceil.
  • Mode Switching: Switch between different implementations of a function based on context (e.g., a fast, unsafe calculation in performance mode vs. a slower, bounds-checked version in debug mode).
  • Runtime Plugin Systems: Load functions from external libraries (DLLs/shared objects) at runtime and bind them to existing function names within the uCalc engine.

💡 Why uCalc? (Comparative Analysis)

uCalc abstracts the platform-specific details of function pointers (C++) and delegates (C#) into a consistent API. This property allows you to manipulate these bindings programmatically at runtime, a task that is typically static and compile-time-dependent in native languages. While delegates and function pointers can be reassigned, uCalc provides a high-level, symbolic way to manage these bindings. You can retrieve an Item by its string name using ItemOf and then change its implementation, a level of dynamism not typically available for compiled functions.

Examples

Defining another function using the same callback address of existing one

ID: 5

				
					using uCalcSoftware;

var uc = new uCalc();
uc.DefineFunction("MyRound(x)", uc.ItemOf("Floor").FunctionAddress);
Console.WriteLine(uc.Eval("MyRound(2.5)"));

uc.ItemOf("MyRound").SetFunctionAddress(uc.ItemOf("Ceil").FunctionAddress);
Console.WriteLine(uc.Eval("MyRound(2.5)"));
				
			
2
3
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

int main() {
   uCalc uc;
   uc.DefineFunction("MyRound(x)", uc.ItemOf("Floor").FunctionAddress());
   cout << uc.Eval("MyRound(2.5)") << endl;

   uc.ItemOf("MyRound").SetFunctionAddress(uc.ItemOf("Ceil").FunctionAddress());
   cout << uc.Eval("MyRound(2.5)") << endl;
}
				
			
2
3
				
					Imports System
Imports uCalcSoftware
Public Module Program
   Public Sub Main()
      Dim uc As New uCalc()
      uc.DefineFunction("MyRound(x)", uc.ItemOf("Floor").FunctionAddress)
      Console.WriteLine(uc.Eval("MyRound(2.5)"))
      
      uc.ItemOf("MyRound").SetFunctionAddress(uc.ItemOf("Ceil").FunctionAddress)
      Console.WriteLine(uc.Eval("MyRound(2.5)"))
   End Sub
End Module
				
			
2
3