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

Macros

#define stType(name)   stType_##name
 
#define stFullType(name)   stFullType_##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, _S"key", int32, 42);
// Expands to:
_htInsert(&ht, stType(string), stArg(string, _S"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 _S
Creates a static ASCII string from a string literal.
Definition strbase.h:392
#define stDestroy(type, pobj,...)
Definition stype.h:1377
#define stType(name)
Definition stype.h:822
#define stFullType(name)
Definition stype.h:876
#define stArg(type, val)
Definition stype.h:937
#define stArgPtr(type, val)
Definition stype.h:990

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 937 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 990 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, _S"key", int32, 42);
// Each type-value pair uses stCheckedArg internally
#define stCheckedArg(type, val)
Definition stype.h:1044

Definition at line 1044 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:267
#define stCheckedPtrArg(type, val)
Definition stype.h:1100

Definition at line 1100 of file stype.h.

◆ stFullType

#define stFullType (   name)    stFullType_##name

(stype, STypeOps*) stFullType(type)

Get a type descriptor and operations pointer for a type name.

Expands to TWO comma-separated values: the type descriptor and a pointer to the operations structure (or NULL for built-in types). Used by low-level type operation functions.

For custom types, specify operations: stFullType(custom(basetype, myOps))

Parameters
nameType name, custom(basetype, ops), or opaque(RealType)
Returns
Type descriptor, operations pointer (TWO values)

Example:

_stDestroy(stFullType(string), gen_ptr);
// Expands to: _stDestroy(stType_string, NULL, gen_ptr)

Definition at line 876 of file stype.h.

◆ stType

#define stType (   name)    stType_##name

stype stType(type)

Get a type descriptor for a type name.

Returns just the stype value without operations. 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 822 of file stype.h.