Skip to content

c_import lays out C's long as 64 bits on Windows: the C type aliases are hardcoded to arm64 macOS #2176

Closed

Description

@ehartford

§16.1 (c_import maps C types to the target's C types); found writing the C-model brief (2026-10-05).

src/CImport.w:710-722 emits the C type aliases once, for every target, under the comment "arm64 macOS: char=signed, int=32, long=64, short=16":

type c_char = i8
type c_long = i64
type c_ulong = u64
type c_longdouble = f64

On Windows long is 32 bits (LLP64), on wasm32 too, and on Linux aarch64 char is unsigned. Repro (installed compiler from main 0ade380, and the Windows build of the same tree):

use c_import("struct S { long a; long b; };\nstatic inline unsigned long s_size(void) { return sizeof(struct S); }\n")
print(f"with {sizeof[S]()} c {s_size()}")
  • macOS: with 16 c 16
  • Windows x86_64: with 16 c 8. With and C disagree on the struct's layout; every field after a long is at the wrong offset, silently.

The migrated corpora inherit it: every defs.w (zlib, pcre2, tommyds, c-algorithms) declares pub type c_long = i64 / pub type c_ulong = u64, so on Windows zlib's uLong is 64 bits where C zlib's is 32.

Expected: the aliases are the target's C types (TargetSpec / TypeLayout already know the data model), and no type c_* alias is emitted into a corpus at all: they are the target's, not the migrating host's.

A related symptom on every host: a program that writes c_ulong with no import fails with "'c_ulong' requires an explicit import (§18.1); add: use std.re.defs.c_ulong". The only declarations of the name are the bundles' Darwin-sized ones.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions