BetterC and Windows API calls

Steven Schveighoffer schveiguy at gmail.com
Fri Jun 2 21:23:46 UTC 2023


On 6/2/23 3:19 PM, pineapple wrote:
> I've been experimenting a bit with betterC recently, and I've found that 
> a trivial use of `QueryPerformanceFrequency` (the extern declaration 
> imported from `core.sys.windows.winbase`) immediately crashes my program 
> with status code 3221225477.
> 
> https://github.com/pineapplemachine/scamp.d/blob/master/src/scamp/time/monotonic.d#L76
> 
> What's going on here? The same code works as expected, without crashing, 
> if I compile without -betterC.
> 
> Before this, I found that trying to use the `core.sys.windows.winbase` 
> module's convenience overrides that accept a long pointer instead of a 
> LARGE_INTEGER struct pointer would result in a linker error when 
> compiling with -betterC.
> 
> Is there something I need to be doing differently to make Windows API 
> calls, or is this a bug with betterC?

That error code is 0xC0000005, which is an access violation (segfault). 
Basically, a memory read/write error.

Using static in D means TLS. I'm not sure what the rules are for TLS and 
betterC, but perhaps it's not properly set up?

Maybe try __gshared instead of static? Not sure.

-Steve


More information about the Digitalmars-d mailing list