11.6. safe_addr macro

The SAFE_ADDR module provides compile-time checked pointer operations. safe_addr returns a temporary pointer to a variable only if the compiler can verify the pointer will not outlive its target. This prevents dangling pointer bugs without runtime overhead.

All functions and symbols are in “safe_addr” module, use require to get access to it.

require daslib/safe_addr

11.6.1. Function annotations

safe_addr::SafeAddrMacro

This macro reports an error if safe_addr is attempted on the object, which is not local to the scope. I.e. if the object can expire while in scope, with delete, garbage collection, or on the C++ side.

safe_addr::SharedAddrMacro

This macro reports an error if shared_addr is attempted on anything other that shared global variables. I.e. only global variables are safe to use with shared_addr.

safe_addr::TempValueMacro

This macro reports an error if temp_value is attempted outside of function arguments.

11.6.2. Safe temporary address

11.6.2.1. safe_addr

safe_addr::safe_addr(x: auto(T) const& ==const) : T?#()

returns temporary pointer to the given expression

Arguments
  • x : auto(T)&!

safe_addr::safe_addr(x: auto(T)& ==const) : T?#()

11.6.2.2. shared_addr

safe_addr::shared_addr(val: auto(VALUE)) : auto()

returns address of the given shared variable. it’s safe because shared variables never go out of scope

Arguments
  • val : auto(VALUE)&

safe_addr::shared_addr(tab: table<auto(KEY), auto(VAL)>; k: KEY) : auto()

11.6.3. Temporary pointers

11.6.3.1. temp_ptr

safe_addr::temp_ptr(x: auto(T)? implicit ==const) : T?#()

returns temporary pointer from a given pointer

Arguments
  • x : auto(T)? implicit!

safe_addr::temp_ptr(x: auto(T)? const implicit ==const) : T?#()

11.6.4. Temporary values

11.6.4.1. temp_value

safe_addr::temp_value(x: auto(T)& ==const) : T&#()

returns temporary reference to the given expression

Arguments
  • x : auto(T)&!

safe_addr::temp_value(x: auto(T) const& ==const) : T const&#()