Landin library reference source

platform/c

Target scope is enforced by the module assertion below.

C scalar aliases selected by the supported LP64 ABI.

The aliases preserve ordinary Landin scalar identity. Plain C char follows the selected ABI, rather than assuming signedness from pointer width. The source assertion and conditional signatures show the exact supported scope; Cortex-M C signatures are not admitted by this module.

compiler.assert(compiler.c_sysv_lp64 or compiler.c_darwin_lp64
                or compiler.c_aapcs64_lp64 or compiler.c_riscv_lp64d)

Items

Executable example

This complete program is maintained in the repository runtime tests. View source.

import platform/c
import platform/c (c_bool, c_double, c_float, c_long, c_longlong, c_ptrdiff,
               c_size, c_ulong, c_ulonglong)

public main: () -> (code: i32) =
    --  c_char is deliberately a signed numeric byte, not Unicode u32.
    character: c.c_char = -1
    signed_character: c.c_schar = -2
    unsigned_character: c.c_uchar = 255
    short_value: c.c_short = -123
    unsigned_short: c.c_ushort = 456
    integer: c.c_int = -789
    unsigned_integer: c.c_uint = 987
    long_value: c.c_long = c_long(integer)
    unsigned_long: c.c_ulong = c_ulong(unsigned_integer)
    long_long: c.c_longlong = c_longlong(long_value)
    unsigned_long_long: c.c_ulonglong = c_ulonglong(unsigned_long)
    size: c.c_size = c_size(24)
    difference: c.c_ptrdiff = c_ptrdiff(-24)
    single: c.c_float = c_float(3)
    double: c.c_double = c_double(single)
    truth: c.c_bool = c_bool(1)

    --  Alias identity permits these ordinary assignments without adapters.
    ordinary_character: i8 = character
    ordinary_short: i16 = short_value
    ordinary_integer: i32 = integer
    ordinary_long: i64 = long_value
    ordinary_unsigned_character: u8 = unsigned_character
    ordinary_unsigned_short: u16 = unsigned_short
    ordinary_unsigned_integer: u32 = unsigned_integer
    ordinary_unsigned_long: u64 = unsigned_long
    ordinary_size: usize = size
    ordinary_difference: isize = difference
    ordinary_single: f32 = single
    ordinary_double: f64 = double
    ordinary_truth: bool = truth

    if sizeof c.c_char == 1 and alignof c.c_char == 1
      and sizeof c.c_schar == 1 and alignof c.c_schar == 1
      and sizeof c.c_uchar == 1 and alignof c.c_uchar == 1
      and sizeof c.c_short == 2 and alignof c.c_short == 2
      and sizeof c.c_ushort == 2 and alignof c.c_ushort == 2
      and sizeof c.c_int == 4 and alignof c.c_int == 4
      and sizeof c.c_uint == 4 and alignof c.c_uint == 4
      and sizeof c.c_long == 8 and alignof c.c_long == 8
      and sizeof c.c_ulong == 8 and alignof c.c_ulong == 8
      and sizeof c.c_longlong == 8 and alignof c.c_longlong == 8
      and sizeof c.c_ulonglong == 8 and alignof c.c_ulonglong == 8
      and sizeof c.c_size == 8 and alignof c.c_size == 8
      and sizeof c.c_ptrdiff == 8 and alignof c.c_ptrdiff == 8
      and sizeof c.c_float == 4 and alignof c.c_float == 4
      and sizeof c.c_double == 8 and alignof c.c_double == 8
      and sizeof c.c_bool == 1 and alignof c.c_bool == 1
      and ordinary_character == -1 and ordinary_short == -123
      and ordinary_integer == -789 and ordinary_long == -789
      and ordinary_unsigned_character == 255 and ordinary_unsigned_short == 456
      and ordinary_unsigned_integer == 987 and ordinary_unsigned_long == 987
      and long_long == -789 and unsigned_long_long == 987
      and ordinary_size == 24 and ordinary_difference == -24
      and ordinary_single == 3.0 and ordinary_double == 3.0
      and ordinary_truth
    then
        code = 42
    else
        code = 1
    end if
end main

c_bool type

public c_bool: type = bool

platform/c/c.ldn:55

Alias for C _Bool under the supported LP64 ABIs.

c_char type

When compiler.c_aapcs64_lp64 or compiler.c_riscv_lp64d

public c_char: type = u8

platform/c/c.ldn:19

The selected ABI's plain C char: unsigned under standard AAPCS64 and RISC-V LP64D, signed under SysV and Darwin LP64. A numeric byte, not a Unicode scalar.

When not (compiler.c_aapcs64_lp64 or compiler.c_riscv_lp64d)

public c_char: type = i8

platform/c/c.ldn:24

The selected ABI's plain C char: unsigned under standard AAPCS64 and RISC-V LP64D, signed under SysV and Darwin LP64. A numeric byte, not a Unicode scalar.

c_double type

public c_double: type = f64

platform/c/c.ldn:53

Alias for C double under the supported LP64 ABIs.

c_float type

public c_float: type = f32

platform/c/c.ldn:51

Alias for C float under the supported LP64 ABIs.

c_int type

public c_int: type = i32

platform/c/c.ldn:35

Alias for C signed int under the supported LP64 ABIs.

c_long type

public c_long: type = i64

platform/c/c.ldn:39

Alias for C signed long under the supported LP64 ABIs.

c_longlong type

public c_longlong: type = i64

platform/c/c.ldn:43

Alias for C signed long long under the supported LP64 ABIs.

c_ptrdiff type

public c_ptrdiff: type = isize

platform/c/c.ldn:49

Alias for C ptrdiff_t under the supported LP64 ABIs.

c_schar type

public c_schar: type = i8

platform/c/c.ldn:27

Alias for C signed char under the supported LP64 ABIs.

c_short type

public c_short: type = i16

platform/c/c.ldn:31

Alias for C signed short under the supported LP64 ABIs.

c_size type

public c_size: type = usize

platform/c/c.ldn:47

Alias for C size_t under the supported LP64 ABIs.

c_uchar type

public c_uchar: type = u8

platform/c/c.ldn:29

Alias for C unsigned char under the supported LP64 ABIs.

c_uint type

public c_uint: type = u32

platform/c/c.ldn:37

Alias for C unsigned int under the supported LP64 ABIs.

c_ulong type

public c_ulong: type = u64

platform/c/c.ldn:41

Alias for C unsigned long under the supported LP64 ABIs.

c_ulonglong type

public c_ulonglong: type = u64

platform/c/c.ldn:45

Alias for C unsigned long long under the supported LP64 ABIs.

c_ushort type

public c_ushort: type = u16

platform/c/c.ldn:33

Alias for C unsigned short under the supported LP64 ABIs.