Varargs issue with LDC

Hipreme msnmancini at hotmail.com
Wed Jan 31 16:19:17 UTC 2024


On Wednesday, 31 January 2024 at 15:25:44 UTC, Don Allen wrote:
> As mentioned in previous posts, I've written a personal finance 
> manager in D (ported from the original C) that works well when 
> compiled with dmd.
>
> When compiled with ldc, however, it segfaults when I try to 
> perform an operation that involves a call to a varargs function 
> in gtk3. The segfault occurs in the
> bowels of gtk3, but a backtrace in gdb shows that the last 
> thing that happened in my code was the call to the varargs 
> function that I refer to above. At this point I am assuming, 
> but do not know, that the issue is related to the varargs 
> nature of the called gtk function.
>
> This is disappointing. Has anyone experienced a similar issue 
> with ldc or knows of known varargs problems with ldc? I did 
> check the ldc github repository and did not find an open issue 
> that sounds similar to what I'm seeing.
>
> This problem occurred on an up-to-date Arch Linux system with 
> the latest release of ldc installed.
>
> /Don Allen

Works well in DMD, crashes on LDC, arguments issue. Take a look 
if you're using the correct `extern(C)` and `extern(D)` in the 
right places. Depending on the compiler you're using, `extern` 
does more than name mangling, it also changes the order in which 
the argument are received.

Also, on a related note: I don't know if you're doing it or not, 
but always mark vararg as `scope`. That means you can't save them 
anywhere, why? Because you really can't. varargs are stack 
allocated so it may also cause a segfault if you try to access 
them after the function exits its scope.

Also, you should post this on Learn instead.


More information about the Digitalmars-d mailing list