-
Notifications
You must be signed in to change notification settings - Fork 254
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
Improve specific literal transpilation #152
Comments
We do not (yet) support translating then compiling on a different platform. I agree that the integer literal should ideally be sized to Long term plan is to replace all conditional defines and platform-specific types with either |
@rinon Hi, thanks for the reply. I think there's two separate concerns, One is the literal itself, the other is the sub operation. |
What about just dropping int literal suffixes and let rust type infer? result = (result as libc::c_long - 0x10000) as libc::c_int That should improve both portability and readability |
@TheDan64 this is actually exactly what i'm doing when remediating the generated code to make it cross-platform. I'm less sure about whether that will cause compilation issues in special cases. |
In most cases we can drop the suffix. However there are occasionally expressions that are ambiguous and require the suffixes to match the semantics of C (Rust defaults to |
Leaving this here for future reference (from https://doc.rust-lang.org/reference/tokens.html#integer-literals):
Edit: we were talking offline about possible ways to fix this, and this list came up. |
This code:
got transpiled into this rust code on x64 linux:
While this is technical correct. The generated code is less portable than the c version.
In fact, on x64 windows, this code will fail to compile with error:
I think this can actually be improved somehow. specifically 0x10000L should be of type
c_long
instead ofi64
.The text was updated successfully, but these errors were encountered: