Luce Base
LuceSourceLuciaOS

22. C to Base

int *p = &x;                 let p: i32* = &x
const T *p                   p: const T*
T *const *pp                 pp: const (T*)*
volatile uint32_t *reg       reg: volatile u32*
void *ctx                    ctx: void*
p->f                         p.f
*p = v                       *p = v
(T *)q                       (T*)q
(uint8_t)x                   (u8)x           # u8(x) is the checked form
(int)f                       (i32)f          # saturating; i32(f) traps
NULL / if (p)                none / if let q = p:
sizeof(T), offsetof(T, f)    memory.size_of(T), memory.offset_of(T, f)
_Static_assert(c, "m")       assert(c, "m")   at module level
T a[N]                       var a: T[N]
char buf[N] = {0};           var buf: u8[N]
char buf[N];                 var buf: u8[N] = ---
T *items, size_t count       items: T[]
char *s                      s: c.str
p = malloc(sizeof(T))        let p = try new T(...)
p = calloc(n, sizeof(T))     let items = try new T[n]
p = malloc(n * sizeof(T))    let items = try new T[n] ---
p = malloc(size)             let bytes = try memory.allocate(size, 16)
free(p)                      free(p)
a / b, a % b (ints)          a // b, a % b    # same truncation as C
x * 31 + c (wrapping)        x *% 31 +% c
x & -x                       x & -%x
if (a + b < a) overflow      let sum = a +? b else ...
a && b, !a                   a and b, not a
goto cleanup                 defer / errdefer
break out of nested loop     outer: for ... / break outer
int f(T *out)                func f() -> (bool, T)
int f(void) /* may fail */   func f() -> !
uint32_t x = byte;           let x: u32 = byte          # widening is implicit
switch                       match, `1, 2, 3:` alternatives, ranges, guards
static int helper()          func helper()   # private by default
static int counter = 3;      var counter: i32 = 3        # module level
_Thread_local int t;         local var t: i32
#include "x.h"               import x
#ifdef __x86_64__            asm x86_64: ... / per-target modules
printf("%d\n", n)            print(f"{n}")
printf("%08x %.2f", n, x)    print(f"{n:08x} {x:.2f}")
LOG("x=%d", x) (macro)       log(f"x={x}")   with a `fmt` parameter
__FILE__, __LINE__           luce.file, luce.line, luce.location
_Atomic int n; n++;          var n: @i32; n += 1
union { int i; float f; }    union Value: / integer: i32 / real: f32
__attribute__((noreturn))    -> never
__attribute__((section(s)))  section(s) func ...