fix value_offset
This commit is contained in:
parent
900341c5b7
commit
1619e3234e
2 changed files with 4 additions and 6 deletions
4
struct.c
4
struct.c
|
|
@ -27,9 +27,7 @@ uint value_size(struct cu_struct_s* st, uint idx, const void* in)
|
|||
uint value_offset(struct cu_struct_s* st, uint idx, const void* in)
|
||||
{
|
||||
uint offset = 0;
|
||||
do {
|
||||
offset += value_size(st, idx, in);
|
||||
} while (idx--);
|
||||
while (idx--) offset += value_size(st, idx, in);
|
||||
return offset;
|
||||
}
|
||||
|
||||
|
|
|
|||
6
test.c
6
test.c
|
|
@ -15,7 +15,7 @@ struct test_s {
|
|||
uint32_t array1[12];
|
||||
uint16_t count;
|
||||
item_t array2[5];
|
||||
} test = {
|
||||
} __attribute__((packed)) test = {
|
||||
.seq = {0},
|
||||
.array1 = {0},
|
||||
.count = 5,
|
||||
|
|
@ -106,8 +106,8 @@ int main()
|
|||
printf("%lx\t%lx\n", 0x12345678abcd8765, h64ton64(0x12345678abcd8765));
|
||||
|
||||
printf("[struct]\n");
|
||||
printf("value_offset\t%u\n", value_offset(CU_STRUCT(test_s), 0, &test));
|
||||
printf("value_size\t%u\n", value_size(CU_STRUCT(test_s), 0, &test));
|
||||
printf("value_offset\t%u\n", value_offset(CU_STRUCT(test_s), 1, &test));
|
||||
printf("value_size\t%u\n", value_size(CU_STRUCT(test_s), 1, &test));
|
||||
|
||||
cutil_exit();
|
||||
return 0;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue