Portál AbcLinuxu, 18. července 2025 09:41
struct S { char text[20]; u_int32_t code; }inicializovanú
S s={"bar",123};tak chcem s.text vidieť ako string "bar" (trebárs aj s nejakým bordelom za tým a nemusí byť ukončený nulou), ale s.code je vždy na rovnakom offset-e.
<struct name="S"> <string name="text" ... /> <primitive name="code" type="UInt32"/> </struct>Podľa https://websvn.kde.org/?revision=1230377&view=revision by to malo byť možné, ale nedarí sa mi
Řešení dotazu:
#include <stdlib.h> #define UINT32 __uint32_t struct S { char text[20]; UINT32 code; }; typedef struct { char text[20]; UINT32 code; } s_t; int main(void) { struct S data = {"text", 123}; s_t data2= {"text", 123}; return 0; }
char text[20];
).
Tak som začal od začiatku a už som myslel, že mám vidiny ... ukázalo sa, že a) string nesmie mať atribút terminatedBy b) zdá sa, že to funguje, ak je maxByteCount dané natvrdo, ale nefunguje to, ak je to tá hodnota v inom člene štruktúry
~/.kde/share/apps/okteta/structures/teststructure
~/.kde/share/apps/okteta/structures/teststructure
<?xml version="1.0" encoding="UTF-8"?> <data xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../structuredefs.xsd"> <struct name="test structure"> <primitive name="textlength" type="UInt16" /> <string name="text" encoding="ascii" updateFunc="function() { this.maxByteCount=this.parent.textlength.value; }" /> <primitive name="code" type="UInt32" /> </struct>
Tiskni
Sdílej:
ISSN 1214-1267, (c) 1999-2007 Stickfish s.r.o.