www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 24310] New: ImportC: varargs from Microsoft header

https://issues.dlang.org/show_bug.cgi?id=24310

          Issue ID: 24310
           Summary: ImportC: varargs from Microsoft header incompatible
                    with va_start
           Product: D
           Version: D2
          Hardware: All
                OS: Windows
            Status: NEW
          Keywords: ImportC
          Severity: normal
          Priority: P3
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: dkorpel live.nl

In Phobos' etc/c/zlib/gzwrite.c file there is a workaround:

---
// needed on Win64 - MS __va_start intrinsic not supported by importC yet
#if __IMPORTC__
    __builtin_va_start(va, format);
#else
    va_start(va, format);
#endif
---

See https://github.com/dlang/phobos/pull/8865#issuecomment-1862006408

---
Argh, the Microsoft headers use something like this (`vadefs.h`) for x86_64:

```c
void __cdecl __va_start(va_list* , ...);
#define __crt_va_start_a(ap, x) ((void)(__va_start(&ap, x)))
```

The signature of their intrinsic isn't compatible with druntime's `va_start`
(which takes the first param as `out` ref, not as explicit pointer), so I sadly
don't see a way to handle this in druntime's `__builtins.di` (or `importc.h`).
---

--
Dec 31 2023