Skip to content

Improve specific literal transpilationΒ #152

@crlf0710

Description

@crlf0710

This code:

  int result = 0;
    if (result > 0x7fff)
      result -= 0x10000L;

got transpiled into this rust code on x64 linux:

    let mut result: libc::c_int = 0i32;
        if result > 0x7fffi32 {
            result = (result as libc::c_long - 0x10000i64) as libc::c_int
        }

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:

     |
1201 |             result = (result as libc::c_long - 0x10000i64) as libc::c_int
     |                                              ^ no implementation for `i32 - i64`
     |
     = help: the trait `std::ops::Sub<i64>` is not implemented for `i32`

I think this can actually be improved somehow. specifically 0x10000L should be of type c_long instead of i64.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions