3

I want to do basic statistics with Vlang.

Can I use C libraries? For example, Apophenia: http://apophenia.info/

Or IMSL C stat library: https://docs.roguewave.com/en/imsl/c/8.6/pdf/C_Stat_library.pdf

Thanks for your help.

rnso
  • 23,686
  • 25
  • 112
  • 234
  • 1
    Since the Vlang home page says "C interop without any costs", the answer is presumably "Yes". You just need to find the right part of the documentation — such as [Calling C functions from V](https://github.com/vlang/v/blob/master/doc/docs.md#calling-c-functions-from-v). – Jonathan Leffler May 22 '20 at 01:59

1 Answers1

5

Yes, you can call C libraries from V.

You need to make the C library's structs, typedefs and functions known to V by defining them in V first - before calling/using them.

For structs you conveniently only need to define the fields you need to use.

Here's some examples:

  • via 2D game framework wrapping several C libs
  • sokol in vlib
  • v-miniaudio wrapper (disclaimer: my own module)

Generally you can find a lot of C wrapper code in vlib itself. (We're working on replacing C with pure V)

Larpon
  • 812
  • 6
  • 19
  • Does Vlang has garbage collection? It is not mentioned on its homepage https://vlang.io/ . – rnso Jul 06 '20 at 01:02
  • 2
    V's memory management model is inspired by https://aardappel.github.io/lobster/memory_management.html + Rust + falling back to reference counting in the worst-case scenarios. So it's a mix. For C interop, though you have to manage memory yourself. This is done through `unsafe` blocks. Where you explicitly tell the compiler "I've got this". – Larpon Jul 07 '20 at 07:27
  • This section is now the official info about memory management: https://github.com/vlang/v/blob/master/doc/docs.md#memory-management – Larpon Jan 17 '21 at 12:58