CX Framework
Cross-platform C utility framework
Loading...
Searching...
No Matches

Macros

#define stvarInit(typen, val)   { .data = { .st_##typen = val }, .type = stType(typen) }
 
#define stvar(typen, val)   ((stvar) { .data = stArg(typen, val), .type = stType(typen) })
 
#define stvNone   ((stvar) { .type = stType(none) })
 

Detailed Description

Macros for creating and initializing variant containers.

Macro Definition Documentation

◆ stvar

#define stvar (   typen,
  val 
)    ((stvar) { .data = stArg(typen, val), .type = stType(typen) })

stvar stvar(type, value)

Create a temporary variant containing a typed value.

Uses C99 compound literals to create a stack-allocated temporary with automatic storage duration. The temporary is valid until the end of the enclosing block scope. This is the primary mechanism for passing typed arguments to variadic functions.

IMPORTANT: The variant's lifetime is limited to the current function scope. Do not return these from functions or store pointers to them beyond the current scope.

Parameters
typenType name (e.g., int32, string, object)
valValue of the specified type
Returns
Temporary stvar with automatic storage duration

Example:

processValue(stvar(int32, 42));
myFunc(3, (stvar[]){
stvar(string, _S"name"),
stvar(int32, 100),
stvar(float64, 3.14)
});
#define _S
Creates a static ASCII string from a string literal.
Definition strbase.h:392
#define stvar(typen, val)
Definition stvar.h:153

Definition at line 153 of file stvar.h.

◆ stvarInit

#define stvarInit (   typen,
  val 
)    { .data = { .st_##typen = val }, .type = stType(typen) }

stvar stvarInit(type, value)

Static initializer for variant structures (C only).

Creates a compile-time initializer suitable for static/automatic variable initialization. This is primarily used when declaring persistent variant variables, not for temporary expressions.

Parameters
typenType name (e.g., int32, string)
valValue of the specified type
Returns
Initializer expression for stvar structure

Example:

stvar persistent = stvarInit(int32, 42);
stvar array[] = {
stvarInit(string, _S"first"),
stvarInit(int32, 100)
};
#define stvarInit(typen, val)
Definition stvar.h:124

Definition at line 124 of file stvar.h.

◆ stvNone

#define stvNone   ((stvar) { .type = stType(none) })

stvar stvNone

Empty variant constant representing no value.

Used to represent the absence of a value or as a sentinel/terminator in variant arrays. The type field is set to stType(none).

Example:

stvar result = stvNone;
if (conditionMet) {
result = stvar(int32, 42);
}
#define stvNone
Definition stvar.h:169

Definition at line 169 of file stvar.h.