Why type of `some_array_size` in your C code and Nim code are different? Also 
type of `buf_len` parameter in C code and Nim code are different.

Here is working code set:

clibfunc.h:
    
    
    #include <stddef.h>
    
    void cfunc(int* buf, size_t buflen);
    
    Run

clibfunc.c:
    
    
    #include <stdio.h>
    #include "clibfunc.h"
    
    void cfunc(int* buf, size_t buflen) {
      for(size_t i = 0; i < buflen; ++i) {
        printf("%d\n", buf[i]);
      }
    }
    
    Run

clibarry.c:
    
    
    #include <stddef.h>
    
    const int carray[] = {12345, 54321};
    const size_t carrayLen = sizeof(carray) / sizeof(carray[0]);
    
    Run

test.nim:
    
    
    {.compile: "clibfunc.c".}
    {.compile: "clibarry.c".}
    
    {.emit: """extern const int carray[];
    extern const size_t carrayLen;
    """.}
    
    let
      carrayLen {.importc, nodecl.}: csize_t
      carray {.importc, nodecl.}: ptr cint
    
    proc cfunc(buf: ptr cint; buflen: csize_t) {.header: "clibfunc.h".}
    
    cfunc(carray, carrayLen)
    
    Run

Compile:
    
    
    $ nim c -r test.nim
    
    Run

Reply via email to