Re: Manage C structures
- Posted by jmduro Sep 25, 2022
- 667 views
Icy_Viking said...
This is pretty neat. Although I'm not sure I fully understand. I can't get the one simple example test I wrote to work correctly.
sequence r = allocateStructure(rect) sequence rs = readStructure(r) for i = 1 to length(rs) do printf(1,"%s",{i}) end for
There were many little errors in your test program:
- you created a structure but didn't write anything in it
- you read an index {i} instead of a structure member {rs[i]}
- you printed a sequence (%s) but you wrote integers (%d)
Here is the corrected code.
include std/dll.e include std/machine.e include std/console.e include common.e include structs.e sequence rect = "struct _rect {" & "int x;" & "int y;" & "int w;" & "int h;" & "} RECT;" sequence r = allocateStructure(rect) writeStructure(r, {10, 20, 50, 100} ) sequence rs = readStructure(r) for i = 1 to length(rs) do printf(1,"%d ",{rs[i]}) end for freeStructure(r) maybe_any_key()
Jean-Marc