You should be able to pass cstring type variable to pointer type parameter without cast. cstring is same to `char*` in C and it is a pointer to char. var val = duckdb_value_varchar(addr(res), col.csize_t, row.csize_t) free(addr(val)) Run
This code is wrong because you are passing the address of a variable to free. You have to pass `val` to `free`. Changing `free` 's parameter from `pointer` to `ptr cstring` does not fix the problem. Don't you get any runtime error in `free(addr(val))`? It should be like this as Araq said: proc free(p: pointer) {.importc: "free", header: "<stdlib.h>".} # duckdb_value_varchar returns cstring var val = duckdb_value_varchar(addr(res), col.csize_t, row.csize_t) echo val free(val) Run It seems writing C library binding without knowing C is dangrous as C compiler cannot checks some errors like this. I think you need to learn C language. When you learn about a C library, you need to read documents written for C programmer. Most of C library bindings for Nim only provides Nim example codes, don't provide detailed documents of each procedures for Nim programmer. When you got a bug in C library, you need to read C code to find it and have to write a minimum and runnable C code that reproduce the bug when you report about the bug to library auther.