-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Add the CTypes
module for common C type aliases
#14448
base: master
Are you sure you want to change the base?
Conversation
# fun bar(x : CTypes::Char*) # okay | ||
# end | ||
# ``` | ||
module CTypes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thought: I was wondering if module C
could be an option as it allows to conveniently write C::Char
. But that would likely cause confusion because A
, B
, C
are commonly used as stub constants.
Importing with a local alias (private alias C = ::CTypes
) would be of similar convenience.
(ref #13504 (comment) ff.)
|
||
# The C `intptr_t` type. | ||
# | ||
# Large enough to hold the value of `Pointer#address`. Equivalent to `Int32` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
question: Is this actually true? Isn't Pointer#address
currently 64-bits on all architectures?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is more like "CTypes::UIntPtrT.new(ptr.address)
should never raise OverflowError
" on any target. And this should be true even if ptr = Pointer(Void).new(UInt64::MAX)
on a 32-bit platform, as LibLLVM.build_int2ptr
will zero-extend or truncate the address.
As stated in the issue: I fail to see the point. What's wrong with |
One of the big benefits of this IMO is having it actually show up in the API docs. Tho a related problem of that is the API docs are essentially going to be "wrong" in that they'll only be applicable to whatever built them. An alternative would be having something in the reference material for this. |
If the docs are being arch specific it might lead to confusion, reference material would be IMO clearer in this regard. |
@Blacksmoke16 Good point. With normal constants we can actually have the generic definition including the macro code that decides the value based on different flags (example Anyway, the doc comments in this PR are pointing out the options, so I don't think it's a big issue. |
With |
See #13504 (comment).