-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Switch int
and uint
to intptr_t
and uintptr_t
respectively, or define cintptr_t
/cuintptr_t
types
#24613
Comments
Well but currently we are compatible with the C types that are more widely used than intptr_t and uintptr_t. The type based aliasing causes troubles either way but there is no evidence we wouldn't introduce even more of this problem with intptr_t. |
uh, the aim here is to ensure that nim code uses the same type as C that it's interacting with, so as to avoid avoidable type aliasing problems - that's broadly done using the same types in nim and C so I don't understand this comment really. You don't introduce problems by using the same type, you introduce them by trying to use the existing nim types which are lacking in this regard. When a C api uses The only question is how, really, and one option is to simply make nim |
Well let me repeat it more clearly. I have no idea if mapping |
If nim is to maintain the |
Even in C's spec Also looking at this document size_t and the like are defined to be type aliases, they are not additional core types. This makes the aliasing rules between e.g |
well, it's not a vote - it's either "it can be done" or "it cannot be done" - the lack of Also: the correct thing to do here is probably both: use |
Alright. |
(as a side note, |
Summary
Make these stdint types available to nim programs for
importc
/exportc
needsDescription
In the current implementation, which integer type
Nim
uses depends on many things, but above all, it is not guaranteed to match the type used inintptr_t
even if their definitions broadly aim to achieve the same thing in both nim and c.This causes problems when trying to interop/importc with code that uses
intptr_t*
and similar pointers, since this may cause a type-based aliasing violation - on some platforms,intptr_t
will be typedefed to Cint
,long
orlong long
depending on the memory model, and even ifint*
andlong*
are of the same size, it is not valid to access the same memory location via them - when there's a mismatch, platform-dependent violations happen.There are a few ways this can be addressed:
intptr_t
anduintptr_t
for Nimint
anduint
and document this in the manual - this can be conditioned on the use of a C99+ compiler and revert back to the currenty method for older c standardscintptr_t
anduintptr_t
as new integer types similar tocint
- at that point, preferably allstdint.h
types would be exposed like thisAlternatives
No response
Examples
No response
Backwards Compatibility
No response
Links
No response
The text was updated successfully, but these errors were encountered: