jameysharp / corrode

C to Rust translator
GNU General Public License v2.0
2.16k stars 116 forks source link

Using Rust to convert simple RosettaCode C-lang tasks #152

Open abhi18av opened 7 years ago

abhi18av commented 7 years ago

Hi again @jameysharp

Have you thought about using Corrode on small-ish C code?

I was experimenting with the C language tasks from RosettaCode but the errors I keep running into are sort of recurrent.

Let's take this for example

a+b-1.c

// Standard input-output streams
#include <stdio.h>
int main()
{
   int a, b;
   scanf("%d%d", &a, &b);
   printf("%d\n", a + b);
   return 0;
}

After running corrode I get two files

a+b-1.rs
a+b-1.o

Only the first one is saved.

I rename it as per rust conventions, so the compiler doesn't complain.

a_plus_b_1.rs

And when I try to compile it with rustc , I run into the following error

❯ rustc a_plus_b_1.rs
error[E0446]: private type `__sFILEX` in public interface
  --> a_plus_b_1.rs:37:5
   |
37 |     pub _extra : *mut __sFILEX,
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^ can't leak private type

error: aborting due to previous error

Then I remove/comment/modify the line 37 and the errors are related to usage of variable, which are to be read through stdin


❯ rustc a_plus_b_1.rs
error[E0381]: use of possibly uninitialized variable: `a`
  --> a_plus_b_1.rs:85:14
   |
85 |         &mut a as (*mut i32),
   |              ^ use of possibly uninitialized `a`

error[E0381]: use of possibly uninitialized variable: `b`
  --> a_plus_b_1.rs:86:14
   |
86 |         &mut b as (*mut i32)
   |              ^ use of possibly uninitialized `b`

error[E0381]: use of possibly uninitialized variable: `a`
  --> a_plus_b_1.rs:88:34
   |
88 |     printf((*b"%d\n\0").as_ptr(),a + b);
   |                                  ^ use of possibly uninitialized `a`

error[E0381]: use of possibly uninitialized variable: `b`
  --> a_plus_b_1.rs:88:38
   |
88 |     printf((*b"%d\n\0").as_ptr(),a + b);
   |                                      ^ use of possibly uninitialized `b`

error: aborting due to 4 previous errors
abhi18av commented 7 years ago

The specific problems that I outlined here might not be that important, I can understand, but the point is RosettaCode could essentially prove to be a great resource for iterating on Corrode. Here's a repository using which you can isolate all the tasks done in C

https://github.com/acmeism/RosettaCodeData

HopperMCS commented 7 years ago

Is @jameysharp still alive?

FSMaxB commented 7 years ago

At least he was still alive 11 hours ago!