Skip to content

Conversation

@kinke
Copy link
Member

@kinke kinke commented May 16, 2018

  • Use it instead of newly introduced, LDC-specific core.stdc.config.c(pp)_(u)int64_t.
  • Cherry-pick Walter's upstream commit replacing the magic structs in core.stdc.config by magic enums (supporting implicit conversion from integer literals) [as well as adding cpp_{size,ptrdiff}_t].
  • Add a clarifying comment wrt. DMD/LDC mangling difference on 64-bit OS X and use version(LDC) guards.
  • Adapt dmd-testsuite accordingly.

@kinke kinke force-pushed the uint64_t branch 2 times, most recently from 4770ebe to 3d8b1bd Compare May 16, 2018 23:59
@JohanEngelen
Copy link
Member

Related: #2650

I find this mangling situation very unfortunate :( Sorry if asking the same question again, I forgot the answer. Is it now that from 2.079 onwards it is necessary to use different D types for C++ interop with DMD and LDC? Is there any way we can prevent that? (either convince DMD to do what we think is sane, or change LDC to do what DMD thinks is sane?)

@kinke
Copy link
Member Author

kinke commented May 17, 2018

A short summary:

  • No different D types need to be used, now that there's proper cpp_(u)long, cpp_{size,ptrdiff}_t and (u)int64_t.
  • With DMD >= 2.079, you can use native D (u)long to represent C++ (unsigned) long long and (u)int64_t, although that's a bad idea as it's not portable (e.g., won't work on Linux x86_64).
  • With LDC, it continues to represent C++ (unsigned) long and {size,ptrdiff}_t, maintaining backwards compatibility and, if you don't care about 32-bit OSX, not requiring an extra import and the ugly cpp_ prefixes for your extern(C++) declarations making ample use of size_t (due to perfect match on all other platforms for both {size,ptrdiff}_t).
  • I tried to convince Walter multiple times already, e.g., just yesterday in change size_t to uint for OSX 64 bit dlang/dmd#8249.

@dnadlinger
Copy link
Member

With LDC, it continues to represent C++ (unsigned) long and {size,ptrdiff}_t

What does "it" refer to here? D [u]long is not of the same width as C++ [unsigned] long on all platforms, e.g. Windows/MSVC.

@kinke
Copy link
Member Author

kinke commented May 17, 2018

The above summary is all 64-bit macOS specific, except for the parts where I mentioned 32-bit macOS and 'other platforms'. So 'it = D (u)long on 64-bit macOS and thus D {size,ptrdiff}_t on 64-bit macOS`.

@kinke
Copy link
Member Author

kinke commented May 17, 2018

[On Windows/MSVC, D (u)long is C++ (unsigned) long long. But so is C++ size_t (for Win64), ergo no issues.]

[Oh and D long is C++ long on all other 64-bit POSIX platforms (and C++ long long on 32-bit POSIX incl. 32-bit Mac).]

* Use it instead of newly introduced, LDC-specific
  `core.stdc.config.c(pp)_(u)int64_t`.
* Cherry-pick Walter's upstream commit replacing the magic structs in
  core.stdc.config by magic enums (supporting implicit conversion from
  integer literals) [as well as adding cpp_{size,ptrdiff}_t].
* Add a clarifying comment wrt. DMD/LDC mangling difference on 64-bit
  OS X and use version(LDC) guards.
* Fix cpp_ptrdiff_t for 32-bit macOS.
* Adapt dmd-testsuite accordingly.
@kinke kinke merged commit 2b6b602 into ldc-developers:master May 20, 2018
@kinke kinke deleted the uint64_t branch May 20, 2018 17:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants