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

Data Structures

struct  stvp
 

Macros

#define stvp(typen, pval)   ((stvp) { stCheckedPtrArg(typen, pval), NULL })
 
#define stvpk(key, typen, pval)   ((stvp) { stCheckedPtrArg(typen, pval), #key })
 
#define stvpNone   ((stvp) { NULL, NULL, NULL })
 

Typedefs

typedef struct stvp stvp
 

Detailed Description

Type-safe variadic destinations, for functions that fill in caller variables rather than reading them.

An stvp is the mirror image of an stvar: where a variant carries a value into a call, an stvp carries a place to put one back out. It pairs a type descriptor with a pointer into the caller's own storage, plus an optional key naming the field it should receive.

This is a passing mechanism, not a variant

An stvp owns nothing, allocates nothing, and lives exactly as long as the call it appears in.

The two are not interchangeable. stvar is a full value container. stvp is a calling convention for a typed pointer to a value.

Usage

The same array-of-struct method stvar uses for input arguments:

// Internal function taking count and destination array
bool _myParse(strref s, int n, stvp *dests);
#define myParse(s, ...) _myParse(s, count_macro_args(__VA_ARGS__), (stvp[]){__VA_ARGS__})
string host = 0;
uint16 port = 443; // untouched if the input has no port
myParse(text, stvpk(host, string, &host), stvpk(port, uint16, &port));
#define stvpk(key, typen, pval)
Definition stvar.h:336
Definition stvar.h:293

Macro Definition Documentation

◆ stvp

#define stvp (   typen,
  pval 
)    ((stvp) { stCheckedPtrArg(typen, pval), NULL })

stvp stvp(type, pval)

Create a positional destination binding.

The pointer is type-checked against the named type at compile time, exactly as stvar() checks a value.

Parameters
typenType name (e.g., int32, string)
pvalPointer to the variable that receives the value
Returns
Temporary stvp with automatic storage duration

Example:

int32 count;
myParse(text, stvp(int32, &count));
#define stvp(typen, pval)
Definition stvar.h:316

Definition at line 316 of file stvar.h.

◆ stvpk

#define stvpk (   key,
  typen,
  pval 
)    ((stvp) { stCheckedPtrArg(typen, pval), #key })

stvp stvpk(key, type, pval)

Create a destination binding tagged with a key name.

Identical to stvp() except that the destination also carries a name, so the receiver fills it in by name rather than by position. The key is written as a bare token and stringized, same as stvark().

Parameters
keyKey name as a bare token (not a string literal)
typenType name (e.g., int32, string)
pvalPointer to the variable that receives the value
Returns
Temporary stvp with automatic storage duration

Example:

uint16 port;
myParse(text, stvpk(port, uint16, &port));

Definition at line 336 of file stvar.h.

◆ stvpNone

#define stvpNone   ((stvp) { NULL, NULL, NULL })

stvp stvpNone

A destination binding that binds nothing.

A variadic call cannot portably be given zero arguments, so this is what to pass when there is genuinely nothing to fill in - matching a pattern purely to find out whether it matches, for instance. Receivers skip it.

Example:

if (strParse(line, _SL("BEGIN ${string(skip)}"), stvpNone)) { ... }
#define _SL(s)
Inline ASCII string literal with compile-time embedded length (STR_LEN8). Content must be < 200 bytes...
Definition strliteral.h:207
#define strParse(s, pat,...)
Definition parse.h:309
#define stvpNone
Definition stvar.h:350

Definition at line 350 of file stvar.h.

Typedef Documentation

◆ stvp

typedef struct stvp stvp

Output parameter binding: a type descriptor plus somewhere to put the value.