Hello, I'm currently exploring Nim's FFI capabilities. I went through the both 
Manual and Tutorial but did not manage to find a detailed explanation on how 
various Nim types are layed out in memory.

Here is what i do understand so far:

  * Adding {.pure.} pragma creates C struct directly mirroring Nim's object 
layout (without any hidden VT fields)
  * It is possible to have a C union via {.union.} pragma



What I basically want to achieve is to create C and Nim type definitions which 
will have the same memory layout. Is it safe to assume the following type 
equality: 
    
    
    C            Nim
    double       float64
    int          int
    size_t       int (with operations though unsigned module)
    int          bool
    

Another problem is the Nim's sequence memory layout. The typical C code for a 
sequence like type (assuming straightforward memory allocation strategy) would 
be: 
    
    
    struct arr {
      size_t len;
      int*   elements;
    };
    

Is there any way to map such a struct to a sequence, so it could be passed 
between Nim and C without copying data? 

Reply via email to