Commit 49a55c42053c368aef1ab4f3b3a752e3cc31f409

Thomas de Grivel 2024-08-19T12:41:04

check sizeof(s_facts_w)

diff --git a/libkc3/struct_type.c b/libkc3/struct_type.c
index 111b904..16a4ad0 100644
--- a/libkc3/struct_type.c
+++ b/libkc3/struct_type.c
@@ -149,7 +149,7 @@ s_struct_type * struct_type_init (s_struct_type *st,
     i++;
     s = list_next(s);
   }
-  tmp.size = offset;
+  tmp.size = (offset + 15) / 16 * 16;
   *st = tmp;
   return st;
 }
diff --git a/misc/fact_w.c b/misc/fact_w.c
index d117dcd..1b58b31 100644
--- a/misc/fact_w.c
+++ b/misc/fact_w.c
@@ -4,13 +4,18 @@
 #include "../http/types.h"
 
 void print_offsets() {
-    printf("Offset of subject: %zu\n", offsetof(struct fact_w, subject));
-    printf("Offset of predicate: %zu\n", offsetof(struct fact_w, predicate));
-    printf("Offset of object: %zu\n", offsetof(struct fact_w, object));
-    printf("Offset of id: %zu\n", offsetof(struct fact_w, id));
 }
 
 int main (void) {
-  print_offsets();
+  printf("offsetof(s_fact_w, subject) = %zu\n",
+         offsetof(s_fact_w, subject));
+  printf("offsetof(s_fact_w, predicate) = %zu\n",
+         offsetof(s_fact_w, predicate));
+  printf("offsetof(s_fact_w, object) = %zu\n",
+         offsetof(s_fact_w, object));
+  printf("offsetof(s_fact_w, id) = %zu\n",
+         offsetof(s_fact_w, id));
+  printf("sizeof(s_fact_w) = %zu\n",
+         sizeof(s_fact_w));
   return 0;
 }
diff --git a/test/ikc3/struct.kc3 b/test/ikc3/struct.kc3
index f4be38d..3266efa 100644
--- a/test/ikc3/struct.kc3
+++ b/test/ikc3/struct.kc3
@@ -16,3 +16,5 @@ quote offsetof(FactW, :object)
 offsetof(FactW, :object)
 quote offsetof(FactW, :id)
 offsetof(FactW, :id)
+quote Sym.type_size(FactW)
+Sym.type_size(FactW)
diff --git a/test/ikc3/struct.out.expected b/test/ikc3/struct.out.expected
index 7f500b4..822a117 100644
--- a/test/ikc3/struct.out.expected
+++ b/test/ikc3/struct.out.expected
@@ -23,3 +23,5 @@ offsetof(FactW, :object)
 (Uw) 224
 offsetof(FactW, :id)
 (Uw) 336
+Sym.type_size(FactW)
+(Uw) 352