Next: , Previous: Callbacks, Up: Operations


6.2.12 Type Conversions

These type conversion functions are very useful for connecting SCM and C code. Most are defined in rope.c.

— Function: SCM long2num (long n)
— Function: SCM ulong2num (unsigned long n)

Return an object of type SCM corresponding to the long or unsigned long argument n. If n cannot be converted, BOOL_F is returned. Which numbers can be converted depends on whether SCM was compiled with the BIGDIG or FLOATS flags.

To convert integer numbers of smaller types (short or char), use the macro MAKINUM(n).

— Function: long num2long (SCM num, char *pos, char *s_caller)
— Function: unsigned long num2ulong (SCM num, char *pos, char *s_caller)
— Function: short num2short (SCM num, char *pos, char *s_caller)
— Function: unsigned short num2ushort (SCM num, char *pos, char *s_caller)
— Function: unsigned char num2uchar (SCM num, char *pos, char *s_caller)
— Function: double num2dbl (SCM num, char *pos, char *s_caller)

These functions are used to check and convert SCM arguments to the named C type. The first argument num is checked to see it it is within the range of the destination type. If so, the converted number is returned. If not, the ASRTER macro calls wta with num and strings pos and s_caller. For a listing of useful predefined pos macros, See C Macros.

Note Inexact numbers are accepted only by num2dbl, num2long, and num2ulong (for when SCM is compiled without bignums). To convert inexact numbers to exact numbers, See inexact->exact.

— Function: unsigned long scm_addr (SCM args, char *s_name)

Returns a pointer (cast to an unsigned long) to the storage corresponding to the location accessed by aref(CAR(args),CDR(args)). The string s_name is used in any messages from error calls by scm_addr.

scm_addr is useful for performing C operations on strings or other uniform arrays (see Uniform Array). — Function: unsigned long scm_base_addr(SCM ra, char *s_name)

Returns a pointer (cast to an unsigned long) to the beginning of storage of array ra. Note that if ra is a shared-array, the strorage accessed this way may be much larger than ra.

Note While you use a pointer returned from scm_addr or scm_base_addr you must keep a pointer to the associated SCM object in a stack allocated variable or GC-protected location in order to assure that SCM does not reuse that storage before you are done with it. See scm_gc_protect.

— Function: SCM makfrom0str (char *src)
— Function: SCM makfromstr (char *src, sizet len)

Return a newly allocated string SCM object copy of the null-terminated string src or the string src of length len, respectively.

— Function: SCM makfromstrs (int argc, char **argv)

Returns a newly allocated SCM list of strings corresponding to the argc length array of null-terminated strings argv. If argv is less than 0, argv is assumed to be NULL terminated. makfromstrs is used by scm_init_from_argv to convert the arguments SCM was called with to a SCM list which is the value of SCM procedure calls to program-arguments (see program-arguments).

— Function: char ** makargvfrmstrs (SCM args, char *s_name)

Returns a NULL terminated list of null-terminated strings copied from the SCM list of strings args. The string s_name is used in messages from error calls by makargvfrmstrs.

makargvfrmstrs is useful for constructing argument lists suitable for passing to main functions.

— Function: void must_free_argv (char **argv)

Frees the storage allocated to create argv by a call to makargvfrmstrs.