www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - What's the correct way to interface with a intptr_t?

reply =?iso-8859-1?Q?Robert_M._M=FCnch?= <robert.muench saphirion.com> writes:
I have a C interface that uses a parameter of type intptr_t. Wondering 
if size_t is the correct D equivalent?

-- 
Robert M. Mnch
http://www.saphirion.com
smarter | better | faster
Apr 06
next sibling parent Alex <sascha.orlov gmail.com> writes:
On Saturday, 6 April 2019 at 19:31:15 UTC, Robert M. Münch wrote:
 I have a C interface that uses a parameter of type intptr_t. 
 Wondering if size_t is the correct D equivalent?
I suppose, ptrdiff_t is. https://dlang.org/spec/type.html#ptrdiff_t https://dlang.org/spec/portability.html#32_to_64bit
Apr 06
prev sibling parent reply Paul Backus <snarwin gmail.com> writes:
On Saturday, 6 April 2019 at 19:31:15 UTC, Robert M. Münch wrote:
 I have a C interface that uses a parameter of type intptr_t. 
 Wondering if size_t is the correct D equivalent?
The correct equivalent is `intptr_t` from `core.stdc.stdint`.
Apr 06
next sibling parent =?iso-8859-1?Q?Robert_M._M=FCnch?= <robert.muench saphirion.com> writes:
On 2019-04-06 20:16:06 +0000, Paul Backus said:

 On Saturday, 6 April 2019 at 19:31:15 UTC, Robert M. Mnch wrote:
 I have a C interface that uses a parameter of type intptr_t. Wondering 
 if size_t is the correct D equivalent?
The correct equivalent is `intptr_t` from `core.stdc.stdint`.
Ha, thanks... RTFM. Will do in the future. -- Robert M. Mnch http://www.saphirion.com smarter | better | faster
Apr 07
prev sibling parent reply bauss <jj_1337 live.dk> writes:
On Saturday, 6 April 2019 at 20:16:06 UTC, Paul Backus wrote:
 On Saturday, 6 April 2019 at 19:31:15 UTC, Robert M. Münch 
 wrote:
 I have a C interface that uses a parameter of type intptr_t. 
 Wondering if size_t is the correct D equivalent?
The correct equivalent is `intptr_t` from `core.stdc.stdint`.
Which is just an alias for ptrdiff_t.
Apr 07
parent reply Paul Backus <snarwin gmail.com> writes:
On Sunday, 7 April 2019 at 12:19:10 UTC, bauss wrote:
 On Saturday, 6 April 2019 at 20:16:06 UTC, Paul Backus wrote:
 On Saturday, 6 April 2019 at 19:31:15 UTC, Robert M. Münch 
 wrote:
 I have a C interface that uses a parameter of type intptr_t. 
 Wondering if size_t is the correct D equivalent?
The correct equivalent is `intptr_t` from `core.stdc.stdint`.
Which is just an alias for ptrdiff_t.
Unless this is guaranteed to be the case on every platform druntime is ever ported to, it is technically better to use the `intptr_t` alias.
Apr 07
parent bauss <jj_1337 live.dk> writes:
On Sunday, 7 April 2019 at 13:45:15 UTC, Paul Backus wrote:
 On Sunday, 7 April 2019 at 12:19:10 UTC, bauss wrote:
 On Saturday, 6 April 2019 at 20:16:06 UTC, Paul Backus wrote:
 On Saturday, 6 April 2019 at 19:31:15 UTC, Robert M. Münch 
 wrote:
 I have a C interface that uses a parameter of type intptr_t. 
 Wondering if size_t is the correct D equivalent?
The correct equivalent is `intptr_t` from `core.stdc.stdint`.
Which is just an alias for ptrdiff_t.
Unless this is guaranteed to be the case on every platform druntime is ever ported to, it is technically better to use the `intptr_t` alias.
It should be guaranteed since it's just supposed to be a signed integer of either 32 bit or 64 bit depending on the architecture you're on. D isn't supported below 32 bit systems so it's irrelevant there and thus it can be a guarantee.
Apr 07