Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

It bears noting that the native Nim FFI is very "thin" & easy. E.g., at least for code anticipated to be compiled by the C backend, you can just declare the C function as a Nim proc (EDITTED to look nicer on mobile):

  proc csetvbuf(f: File,
                buf: pointer,
                mode: cint,
                size: csize):
    cint {.importc: "setvbuf",
           header: "stdio.h".}
  # ...intervening code...
  discard csetvbuf(stdout, nil,
                   0, 16384)
c2nim is more helpful for larger C APIs with a lot of C structs and a wide set of entrypoints/API calls. For simple enough C code it can be used as a "starting point" to port the whole thing, but you will probably at least want to change things like a1, a2, etc. parameter names ("a" for "argument"). Nim has named arguments (like Python, f(x=2)) so such names are a bit more important. (Not that all code meant to be read by a human should not have good param names.)


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: