ImportC and #pragma pack

Guillaume Piolat first.name at notexisting.com
Tue Sep 28 19:52:32 UTC 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.



More information about the Digitalmars-d mailing list