[SAOC 2026] ImportC Weekly Update #10

Niyati Jain niyati.jainn15 at gmail.com
Sun Nov 29 18:19:20 UTC 2026


I started this week with #21265, where `#pragma comment(lib, 
"name")` was being silently dropped by ImportC's `#pragma` 
handling. Fed the library name into D's existing `pragma(lib, 
"name")` mechanism once the parser recognizes the `lib` 
comment-type. My first version built that AST node inline where 
the directive was parsed, but that path is required to be nothrow 
and the AST constructors aren't, so it failed. Then, I found in 
the issue itself, @drpriver already had an unopened branch for 
this exact issue with better direction, to collect the name 
during parsing, build the AST only once the whole file's done. 
So, I rewrote it that way. That branch also left an open question 
if it still work if the C file is only imported, never separately 
compiled, to which I confirmed and yes, same as how D's own 
`pragma(lib)` already works across imports.
Merged (https://github.com/dlang/dmd/pull/24484).

Next was `~`/`!` macros. ImportC already turns `#define ID 
FUNC(args)` into a template function since #22347, reasoning that 
a bare call is precedence-safe to wrap. Extended that to a 
leading `~` or `!`, same precedence tier.
Merged (https://github.com/dlang/dmd/pull/24483).

Then the `##` suffix case, `#define SDL_UINT64_C(c) c##ULL`. 
Recognized this one narrow shape, a macro's single parameter 
pasted with a fixed numeric suffix, and turned it into a cast 
instead of token pasting, since the suffix only ever fixes the 
literal's type. Real bug, continuing to parse after the body hit 
the first `#` kept failing, the lexer treats any bare `#` as a 
possible nested directive and skips the rest of the line looking 
for one, taking up the suffix text too. So I had to check the raw 
buffer directly before tokenizing instead, also I checked this 
against what Walter already ruled out years back in the thread 
(https://github.com/dlang/dmd/pull/15871#issuecomment-1836657895), real token pasting, this is narrower than that. So it turned out bigger than expected, glibc's real `<stdint.h>` uses the same shape for `INT64_C`/`UINT64_C`, breaking `INT64_MAX`/`UINT64_MAX` too.
Merged (https://github.com/dlang/dmd/pull/24490).

Then I picked up a separate bug along the way, #24374, 
`-i=package.module` patterns ignoring an explicit `__module` 
declaration in a C file. Traced it to the include/exclude 
decision being made before the file's module header was even 
parsed, so the `__module` statement hadn't been seen yet. Matched 
the ordering the D-side parser already uses for exactly this 
reason.
Merged (https://github.com/dlang/dmd/pull/24485).

Also filed #24462, on whether dmd should auto-link default Win32 
libs on Windows targets that came out of tracing #21815's 
remaining `__imp_MapViewOfFileNuma2` symbol, which isn't a pragma 
problem, instead it's just `kernel32.lib` missing from the link 
line.
https://github.com/dlang/dmd/issues/24462.

Next, I'll go through curl's and SDL's real headers now that 
bare-identifier, `~`/`!`, and `##`-suffix macros are handled, to 
see what's actually left.

Thanks to Nicholas for the constant guidance on all of this.

Any feedback or suggestion is highly welcomed.

Best,
Niyati


More information about the Digitalmars-d mailing list