September 28, 2021
On Tuesday, 28 September 2021 at 08:54:00 UTC, max haughton wrote:
> On Tuesday, 28 September 2021 at 06:30:09 UTC, Elronnd wrote:
>> On Tuesday, 28 September 2021 at 06:05:04 UTC, Walter Bright wrote:
>>> How far do we go with implementing all the nutburger obsolete C extension cruft out there?
>>
>> The whole point of importc is compatibility, no?  So I say: all the way.
>
> Compatibility with what? Are there projects using pragma pack as part of a stable API?

Absolutely.
For example the VST3 SDK https://github.com/steinbergmedia/vst3_pluginterfaces/blob/b8566ef3b2a0cba60a96e3ef2001224c865c8b36/base/falignpush.h

This header is then included before every struct definition.
It's very easy after a D translation to have an ABI problem because of this, so SDK writers have written sizeof checks.
September 29, 2021
Out of that list linux and SDL2 probably are the most likely to work short term, so yeah that changes things.
September 28, 2021
On Tuesday, 28 September 2021 at 06:05:04 UTC, Walter Bright wrote:
> https://issues.dlang.org/show_bug.cgi?id=22315
>
> I'm on the fence about implementing this. On the one hand, I can do it and make it work. On the other hand, the C11 way is to use _Alignas, and that's 10 years old now. How far do we go with implementing all the nutburger obsolete C extension cruft out there?

Is there an alternative that could be suggested? For instance, throwing an error message but explaining how to use `_Alignas`? If not, I'm not sure what choice there is.
September 28, 2021
On 9/28/2021 5:54 AM, Guillaume Piolat wrote:
> For example the VST3 SDK https://github.com/steinbergmedia/vst3_pluginterfaces/blob/b8566ef3b2a0cba60a96e3ef2001224c865c8b36/base/falignpush.h 
> 
> 
> This header is then included before every struct definition.
> It's very easy after a D translation to have an ABI problem because of this, so SDK writers have written sizeof checks.

Filed a bug report on it:
https://github.com/steinbergmedia/vst3_pluginterfaces/issues/9

While that won't change our decision, I encourage people to file bug reports on projects that use #pragma pack.
September 28, 2021
On 9/28/2021 5:45 AM, russhy wrote:
> It's quite common to see #pragma pack used in gamedev libraries when you need to squeeze every little bit for performance

The point is C11 specifies using _Alignas, and by now all used C compilers should support that.
September 28, 2021
On 9/28/2021 5:50 AM, Guillaume Piolat wrote:
> The conundrum with ImportC is that it seems to me you have to build with the right cstdlib headers if you intend to use this or that backend.

Not sure what that means.

> So in the end I managed to convert none of the STB headers libraries with ImportC (not only due to pragma pack).

Please enumerate the issues you found.

September 28, 2021
On Tuesday, 28 September 2021 at 17:28:54 UTC, Walter Bright wrote:
>
> While that won't change our decision, I encourage people to file bug reports on projects that use #pragma pack.

If so many C and C++ compilers started implementing #pragma pack to support these projects, it is doubtful these projects will move one bit for supporting a D compiler. Anyway.

September 28, 2021
On Tuesday, 28 September 2021 at 17:32:26 UTC, Walter Bright wrote:
> On 9/28/2021 5:50 AM, Guillaume Piolat wrote:
>> The conundrum with ImportC is that it seems to me you have to build with the right cstdlib headers if you intend to use this or that backend.
>
> Not sure what that means.

I mean that the ImportC preprocessor needs libc headers, and those SHOULD be the same libc that the code will be linked against.

1. Suppose you use ImportC right now, using the TinyCC with its own cstlib headers, for the purpose of preprocessing C code in order to give to ImportC.

The preprocessed C code has the following `dirent` struct:
https://github.com/TinyCC/tinycc/blob/82b0af74501bf46b16bc2a4a9bd54239aa7b7127/win32/include/dirent.h#L25

2. You link with the libc that comes with DMD or LDC, so the clang or msvc or Digital Mars one. They contains another `dirent` struct definition

3. At runtime, the C stdlib has its own understanding of what is the `dirent` struct. A memory corruption ensues right after calling readdir() and reading the result.

September 28, 2021
On 9/28/2021 12:40 PM, Guillaume Piolat wrote:
> On Tuesday, 28 September 2021 at 17:28:54 UTC, Walter Bright wrote:
>>
>> While that won't change our decision, I encourage people to file bug reports on projects that use #pragma pack.
> 
> If so many C and C++ compilers started implementing #pragma pack to support these projects, it is doubtful these projects will move one bit for supporting a D compiler. Anyway.

I'm used to my bug reports being ignored!

Anyhow, pointing out non-standard constructs that can be replaced with standard ones is good for everyone, not just D.

September 28, 2021
On 9/28/2021 12:52 PM, Guillaume Piolat wrote:
> On Tuesday, 28 September 2021 at 17:32:26 UTC, Walter Bright wrote:
>> On 9/28/2021 5:50 AM, Guillaume Piolat wrote:
>>> The conundrum with ImportC is that it seems to me you have to build with the right cstdlib headers if you intend to use this or that backend.
>>
>> Not sure what that means.
> 
> I mean that the ImportC preprocessor needs libc headers, and those SHOULD be the same libc that the code will be linked against.

Just like for any C code, the .h files must match the library binaries.


> 1. Suppose you use ImportC right now, using the TinyCC with its own cstlib headers, for the purpose of preprocessing C code in order to give to ImportC.
> 
> The preprocessed C code has the following `dirent` struct:
> https://github.com/TinyCC/tinycc/blob/82b0af74501bf46b16bc2a4a9bd54239aa7b7127/win32/include/dirent.h#L25 
> 
> 
> 2. You link with the libc that comes with DMD or LDC, so the clang or msvc or Digital Mars one. They contains another `dirent` struct definition
> 
> 3. At runtime, the C stdlib has its own understanding of what is the `dirent` struct. A memory corruption ensues right after calling readdir() and reading the result.

Of course that will fail, just like it will fail if you compile code with TinyCC's stdlib and link with clang's stdlib.