Output parameters in C
Factor handbook » C library interface » Passing data between Factor and C

Prev:C strings
Next:C value boxes


A frequently-occurring idiom in C code is the "out parameter". If a C function returns more than one value, the caller passes pointers of the correct type, and the C function writes its return values to those locations.
with-out-parameters ( c-types quot -- values... )

The idiom is commonly used for passing back an error message if the function calls fails. For example, if a function is declared in the following way:
FUNCTION: int do_frob ( int arg1, char** errptr )

Then it could return 1 on error and 0 otherwise. A correct way to call it would be:
1234 { c-string } [ do_frob ] with-out-parameters

which would put the function's return value and error string on the stack.