forum-msg-id-132293-edit
Original date:2018-03-31 06:05:04 Edited by: petelomax Subject: Re: Important question?
begin said...
how do you deal properly with *next, *data when using the struct from phix?
OK, cffi.e did not handle void* (or TT*) properly(!!!); you will need to grab the latest copy of builtins/cffi.e from the repository.
(At least that demonstrates my point that cffi.e is maintainable, the changes needed were somewhat easier, both for me to make and you to download, than modifying the compiler itself!)
include cffi.e -- NOTE: this is a triple_quote, for some reason not displaying right on this forum: constant tTT = """ typedef struct TT { int i; // .... void *data; TT *next; } """
constant integer idTT = define_struct(tTT) atom pList = NULL procedure push(integer i) atom pTT = allocate_struct(idTT) set_struct_field(idTT,pTT,"i",i) set_struct_field(idTT,pTT,"data",pList) set_struct_field(idTT,pTT,"next",pList) pList = pTT end procedure function pop() atom pTT = pList pList = get_struct_field(idTT,pTT,"next") sequence res = {get_struct_field(idTT,pTT,"i"), get_struct_field(idTT,pTT,"data"), get_struct_field(idTT,pTT,"next")} free(pTT) return res end function for i=1 to 3 do push(i) end for for i=1 to 3 do ?pop() end for
output:
{3,42415824,42415824} {2,42094328,42094328} {1,0,0}
Regards,
Pete
PS: the triple quote appears quite different in the preview to when actually posted, as well, so I split the <eucode> in two.
Not Categorized, Please Help
|