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

Using C from Cone: calling fopen() #65

Open
jt9897253 opened this issue Oct 3, 2022 · 1 comment
Open

Using C from Cone: calling fopen() #65

jt9897253 opened this issue Oct 3, 2022 · 1 comment

Comments

@jt9897253
Copy link

Hello,

when trying to call fopen() from cone, the program exits with a segmentation fault.
This is tested on macOS, the code is:

import stdio::*

struct @opaque file

extern:
  fn fopen(filename &[]u8, mode &[]u8) *file

fn main():
  mut testFile = fopen("test", "w")

Is it possible to call fopen() from cone, and if yes, could you please give me a hint how to do it?
Thank you!

@jondgoodwin
Copy link
Owner

The biggest problem I see with your code is that you define fopen as accepting two array references (slices). fopen is written to expect pointers. An array reference is a "fat pointer", composed of a pointer plus a length.

It might work better to define with fn fopen(filename *u8, mode *u8).

Let me know if that helps. If not, I can look into it more when I have time (though I don't have a macintosh).

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