C Types¶
Idio supports the use of the fourteen C base types and typedefs thereof and a pointer type:
Idio |
C |
|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Equality tests of C/longdouble are, at best, untested.
The C/pointer type is used to carry references to C
allocated memory. They will usually be tagged such that the GC will
free the referenced memory when it collects the value.
There is a special form of C/pointer with a C Structure
Identifier tag which allows for the implicit use of accessors and
printers of that value. Most of the allocated C structs in libc are so tagged.
C Type Predicates¶
- function C/char? o¶
test if o is a C/char
- Param o:
object to test
- Return:
#tif o is a C/char,#fotherwise
- function C/schar? o¶
test if o is a C/schar
- Param o:
object to test
- Return:
#tif o is a C/schar,#fotherwise
- function C/uchar? o¶
test if o is a C/uchar
- Param o:
object to test
- Return:
#tif o is a C/uchar,#fotherwise
- function C/short? o¶
test if o is a C/short
- Param o:
object to test
- Return:
#tif o is a C/short,#fotherwise
- function C/ushort? o¶
test if o is a C/ushort
- Param o:
object to test
- Return:
#tif o is a C/ushort,#fotherwise
- function C/int? o¶
test if o is a C/int
- Param o:
object to test
- Return:
#tif o is a C/int,#fotherwise
- function C/uint? o¶
test if o is a C/uint
- Param o:
object to test
- Return:
#tif o is a C/uint,#fotherwise
- function C/long? o¶
test if o is a C/long
- Param o:
object to test
- Return:
#tif o is a C/long,#fotherwise
- function C/ulong? o¶
test if o is a C/ulong
- Param o:
object to test
- Return:
#tif o is a C/ulong,#fotherwise
- function C/longlong? o¶
test if o is a C/longlong
- Param o:
object to test
- Return:
#tif o is a C/longlong,#fotherwise
- function C/ulonglong? o¶
test if o is a C/ulonglong
- Param o:
object to test
- Return:
#tif o is a C/ulonglong,#fotherwise
- function C/float? o¶
test if o is a C/float
- Param o:
object to test
- Return:
#tif o is a C/float,#fotherwise
- function C/double? o¶
test if o is a C/double
- Param o:
object to test
- Return:
#tif o is a C/double,#fotherwise
- function C/longdouble? o¶
test if o is a C/longdouble
- Param o:
object to test
- Return:
#tif o is a C/longdouble,#fotherwise
- function C/pointer? o¶
test if o is a C/pointer
- Param o:
object to test
- Return:
#tif o is a C/pointer,#fotherwise
- function C/type? o¶
test if o is any C type
- Param o:
object to test
- Return:
#tif o is any C type,#fotherwise
- function C/number? o¶
test if o is any C numeric type
- Param o:
object to test
- Return:
#tif o is any C numeric type,#fotherwise
- function C/integral? o¶
test if o is any C integral numeric type
- Param o:
object to test
- Return:
#tif o is any C integral numeric type,#fotherwise
- function C/signed? o¶
test if o is any C signed numeric type
- Param o:
object to test
- Return:
#tif o is any C signed numeric type,#fotherwise
- function C/unsigned? o¶
test if o is any C unsigned numeric type
- Param o:
object to test
- Return:
#tif o is any C unsigned numeric type,#fotherwise
- function C/floating? o¶
test if o is a C floating point type
- Param o:
object to test
- Return:
#tif o is a C floating point type,#fotherwise
C Type Constructors¶
- function C/integer-> i [type]¶
convert Idio integer i to a C integer
If i is a fixnum then use type for a more specific C type.
An integer bignum is converted to a
libc/intmax_t.- Param i:
Idio integer to convert
- Type i:
fixnum or bignum
- Param type:
C type to create, defaults to
'int- Type type:
symbol, optional
- Return:
C integer
- Rtype:
according to type
- Raises:
^rt-C-conversion-error:
type defaults to
'intand can be one of:'char'schar'uchar'short'ushort'int'uint'long'ulong'longlong'ulonglongor an alias thereof, eg.libc/pid_t.i is range-checked for type
C/integer->is limited to a Cintmax_t, see C/integer->unsigned
- function C/integer->unsigned i [C/unsigned type]¶
convert Idio integer i to a C unsigned integer
If i is a fixnum then use type for a more specific C type.
An integer bignum is converted to a
libc/uintmax_t.- Param i:
Idio integer to convert
- Type i:
bignum or fixnum
- Param type:
C type to create, defaults to
'uint- Type type:
symbol, optional
- Return:
C unsigned integer
- Rtype:
according to type
- Raises:
^rt-C-conversion-error:
type defaults to
'uintand can be one of:'uchar'ushort'uint'ulong'ulonglongor an alias thereof, eg.libc/size_t.i is range-checked for type
C/integer->unsignedis limited to a Cuintmax_t
- function C/number-> n type¶
convert Idio number n to a C number using type for the specific C type.
bignums must be a C floating type
- Param n:
Idio number to convert
- Type n:
fixnum or bignum
- Param type:
C type to create
- Type type:
symbol
- Return:
C number
- Rtype:
according to type
- Raises:
^rt-C-conversion-error:
type can be one of:
'char'schar'uchar'short'ushort'int'uint'long'ulong'longlong'ulonglong'float'double'longdoubleor an alias thereof, eg.libc/size_t.n is range-checked for integral types
Where type is:
signed, C/integer-> is called,
unsigned, C/integer->unsigned is called,
Warning
If n is a bignum then type can only be a floating point type.
C Type Converters¶
- function C/->integer i¶
convert C integer i to an Idio integer
- Param o:
C integer to convert
- Type o:
C/ integer type
- Return:
Idio integer
- Rtype:
integer
- function C/->number i¶
convert C number i to an Idio number
- Param o:
C number to convert
- Type o:
a C/ numeric type
- Return:
Idio number
- Rtype:
number
supported C types are:
C/charC/scharC/ucharC/shortC/ushortC/intC/uintC/longC/ulongC/longlongC/ulonglongC/floatC/doubleor an alias thereof, eg.libc/size_t.the following types are NOT supported:
C/longdouble
C Pointer Reflection¶
C pointers can be tagged with some C Structure Identification (CSI) information. The purpose is multi-fold where, using libc/struct-stat as an example:
we can store a nominal structure name, eg.
libc/struct-statThe name is descriptive only.
we can store a list of the structure members, eg.
libc/struct-stat’s:(st_dev st_ino st_nlink st_mode st_uid st_gid st_rdev st_size st_blksize st_blocks st_atim st_mtim st_ctim st_atime st_mtime st_ctime)Note
The modern C
struct statdoes not havest_atimeetc. members per se but those are#define’d to thetime_t tv_seccomponents of the correspondingst_atim’sstruct timespecthus maintaining backwards compatibility.Idio supports accessing both forms.
we can associate a getter to manipulate the
C/pointergiven a member name, here, libc/struct-stat-refWe can subsequently associate a setter with the getter – albeit there is (deliberately) no setter for a
libc/struct-stat.we can associate a function to print the
C/pointerin a more aesthetically pleasing manner. For example, thestruct timespecis stylised as a floating point number.Here, we associate libc/struct-stat-as-string.
- function C/pointer-name p¶
Return the CSI name of C/pointer p
- Param p:
C/pointer to query
- Type p:
C/pointer
- Return:
CSI name or
#n- Rtype:
symbol or
#n
The CSI name is descriptive only.
- function C/pointer-members p¶
Return the CSI members of C/pointer p
- Param p:
C/pointer to query
- Type p:
C/pointer
- Return:
CSI members or
#n- Rtype:
list
Last built at 2025-10-29T07:10:35Z+0000 from 3d9f9d3 (dev) for Idio 0.3.b.6