I would like to translate old, C code (+12k clocs, 50 .c + 1 .h files) to nim. The C program compiles fine with clang 3.8/gcc 6.1. My idea was to start with smallest C files, say foobar.c + bigfat.h, use c2nim (+ including the bigfat.h header), get foobar.nim + bigfat.nim, change as little as possible [1] just that I get nim->C compilation, sat to foobar_nim.c, then compile the whole project as "normal" C source tree. Here is the minimal bigfat.h:
typedef struct a_node *pnode;
typedef struct a_node
{
char s[MYCONST];
int somekey;
pnode next;
} node;
I am getting .nim files (foobar.nim + bigfat.nim), but nim c produces: foobar.nim(2, 16) Error: undeclared identifier: 'a_node'
Here is the bigfat.nim:
type
pnode* = ptr a_node
node* {.importc: "node", header: "bigfat.h".} = object
s* {.importc: "s".}: array[MYCONST, char]
somekey* {.importc: "somekey".}: cint
next* {.importc: "next".}: pnode
The linked lists are in bunch of other C-code project files files. Hence my question: what can I do to fix it?
I have no problem with "almost the old C code but in nim" (code beauty be dammed for time being assuming the mostly-C + one file C-masked as nim compiles and runs as expected).
thank you for your help
Hello, try
const MYCONST = 3
type
pnode* = ptr a_node
a_node* {.importc: "a_node", header: "bigfat.h".} = object
s* {.importc: "s".}: array[MYCONST, char]
somekey* {.importc: "somekey".}: cint
next* {.importc: "next".}: pnode