Skip to content
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

Wrong output when doing addition on short #2

Open
bungcip opened this issue May 23, 2017 · 3 comments
Open

Wrong output when doing addition on short #2

bungcip opened this issue May 23, 2017 · 3 comments

Comments

@bungcip
Copy link

bungcip commented May 23, 2017

#include <iostream>
using namespace std;

int main() {
    
    short a = 32767;
    short b = 32767;
    int c = a + b;
    cout<<c;
}

Current crust will produce something like this

...
 fn main ( ) {
   ...
   let mut a : i16 = 32767 ; let mut b : i16 = 32767 ; 
   let mut c : i32 = a+b ;  // ~~> wrong
   ...
 }

Its seems crust don't handle c integer promotion from short to int.

@NishanthSpShetty
Copy link
Owner

Hi
It require you to add cast manually.

@bungcip
Copy link
Author

bungcip commented May 24, 2017

Hi @NishanthSpShetty,
Ideally crust will be automatically handling the cast, I know this issue will be tough to solve in current crust state. It will require some semantic analysis on the C code. However crust will need semantic & flow control analysis if you plan to support goto

@NishanthSpShetty
Copy link
Owner

@bungcip
Yeah..you are correct. Semantic analysis and flow controller analysis required, which may solve lot of issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants