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

Macros

#define stType(name)   (&stTypeInfo(name))
 
#define stArg(type, val)   STypeArg_##type(type, val)
 
#define stArgPtr(type, val)   STypeArgPtr_##type(type, val)
 
#define stCheckedArg(type, val)   STypeCheckedArg_##type(type, val)
 
#define stCheckedPtrArg(type, val)   STypeCheckedPtrArg_##type(type, val)
 

Detailed Description

Macros for passing typed values through generic function interfaces.

The CX framework uses a macro-based system for type-safe generic functions. Instead of traditional C varargs or void pointers, functions take type-value pairs that expand to type descriptors and type-checked containers.

Four levels of argument passing:

  1. stType(type) - Type descriptor only (stype value)
  2. stFullType(type) - Type descriptor + operations pointer (stype, STypeOps*)
  3. stArg(type, val) - Type-checked value in generic container (stgeneric)
  4. stCheckedArg(type, val) - Complete: descriptor + checked value (stype, stgeneric)

Usage patterns:

// Simple type descriptor
stype t = stType(int32);
// Generic container operations
htInsert(&ht, string, _SL("key"), int32, 42);
// Expands to:
_htInsert(&ht, stType(string), stArg(string, _SL("key")),
stType(int32), stArg(int32, 42));
// Low-level operations with full type info
stDestroy(string, &s);
// Expands to:
_stDestroy(stFullType(string), stArgPtr(string, &s));
#define htInsert(htbl, ktype, key, vtype, val,...)
Definition hashtable.h:443
#define _SL(s)
Inline ASCII string literal with compile-time embedded length (STR_LEN8). Content must be < 200 bytes...
Definition strliteral.h:207
#define stDestroy(type, pobj,...)
Definition stype.h:1617
#define stType(name)
Definition stype.h:972
#define stArg(type, val)
Definition stype.h:1036
#define stArgPtr(type, val)
Definition stype.h:1091

The pointer variants (stArgPtr, stCheckedPtrArg) are used for output parameters or when the function needs to modify/consume the value.

Macro Definition Documentation

◆ stArg

#define stArg (   type,
  val 
)    STypeArg_##type(type, val)

stgeneric stArg(type, value)

Pack a typed value into a generic container with compile-time type checking.

Converts a value of any supported type into an stgeneric union that can be passed through generic function interfaces. Performs type checking to ensure the value is compatible with the specified type.

Special handling:

  • Primitives: Stored directly in the union
  • Objects/handles: Stored as pointers
  • opaque: Requires an lvalue, takes its address
  • SUID/stvar: Too large for union, creates stack temporary and passes pointer
Parameters
typeType name
valValue to pack
Returns
Generic container holding the value

Example:

stgeneric gen = stArg(int32, 42);
stgeneric gen_str = stArg(string, s);

Definition at line 1036 of file stype.h.

◆ stArgPtr

#define stArgPtr (   type,
  val 
)    STypeArgPtr_##type(type, val)

stgeneric* stArgPtr(type, pointer)

Create a pointer to a generic container from a pointer to a typed value.

Used for output parameters or when a function needs to modify or consume the value. For most types, casts the pointer to stgeneric*. For opaque types, wraps the pointer in a generic container.

Parameters
typeType name
valPointer to the value
Returns
Pointer to generic container

Example:

int32 i;
stgeneric* gen_ptr = stArgPtr(int32, &i);

Definition at line 1091 of file stype.h.

◆ stCheckedArg

#define stCheckedArg (   type,
  val 
)    STypeCheckedArg_##type(type, val)

(stype, stgeneric) stCheckedArg(type, value)

Complete argument package: type descriptor + type-checked value.

Expands to TWO comma-separated values for passing to functions that take runtime type parameters. Combines stType() and stArg() into a single call. This is the most common form for generic function parameters.

Parameters
typeType name
valValue to pass
Returns
Type descriptor, generic container (TWO values)

Example:

_saPush(handle, stCheckedArg(int32, 42));
// Expands to: _saPush(handle, stType(int32), stArg(int32, 42))
htInsert(&ht, string, _SL("key"), int32, 42);
// Each type-value pair uses stCheckedArg internally
#define stCheckedArg(type, val)
Definition stype.h:1147

Definition at line 1147 of file stype.h.

◆ stCheckedPtrArg

#define stCheckedPtrArg (   type,
  val 
)    STypeCheckedPtrArg_##type(type, val)

(stype, stgeneric*) stCheckedPtrArg(type, pointer)

Complete argument package for pointer parameters: type descriptor + pointer.

Expands to TWO comma-separated values for passing to functions that need to modify or consume the value. Combines stType() and stArgPtr() into a single call. Used for output parameters and value consumption.

Parameters
typeType name
valPointer to the value
Returns
Type descriptor, pointer to generic container (TWO values)

Example:

int32 result;
_someFunc(stCheckedPtrArg(int32, &result));
// Expands to: _someFunc(stType(int32), stArgPtr(int32, &result))
ssdCopyOut(root, path, int32, &val);
// Uses stCheckedPtrArg internally for the output parameter
#define ssdCopyOut(root, path, vtype, val_copy_out)
Definition ssdtree.h:269
#define stCheckedPtrArg(type, val)
Definition stype.h:1205

Definition at line 1205 of file stype.h.

◆ stType

#define stType (   name)    (&stTypeInfo(name))

stype stType(type)

Get a type descriptor for a type name.

For opaque types, can specify the real structure type: stType(opaque(MyStruct))

Parameters
nameType name or opaque(RealType)
Returns
Type descriptor

Example:

stype st = stType(int32);
stype st_custom = stType(opaque(MyStruct));

Definition at line 972 of file stype.h.