offsets.c 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /* Area: Struct layout
  2. Purpose: Test ffi_get_struct_offsets
  3. Limitations: none.
  4. PR: none.
  5. Originator: Tom Tromey. */
  6. /* { dg-do run } */
  7. #include "ffitest.h"
  8. #include <stddef.h>
  9. struct test_1
  10. {
  11. char c;
  12. float f;
  13. char c2;
  14. int i;
  15. };
  16. int
  17. main (void)
  18. {
  19. ffi_type test_1_type;
  20. ffi_type *test_1_elements[5];
  21. size_t test_1_offsets[4];
  22. test_1_elements[0] = &ffi_type_schar;
  23. test_1_elements[1] = &ffi_type_float;
  24. test_1_elements[2] = &ffi_type_schar;
  25. test_1_elements[3] = &ffi_type_sint;
  26. test_1_elements[4] = NULL;
  27. test_1_type.size = 0;
  28. test_1_type.alignment = 0;
  29. test_1_type.type = FFI_TYPE_STRUCT;
  30. test_1_type.elements = test_1_elements;
  31. CHECK (ffi_get_struct_offsets (FFI_DEFAULT_ABI, &test_1_type, test_1_offsets)
  32. == FFI_OK);
  33. CHECK (test_1_type.size == sizeof (struct test_1));
  34. CHECK (offsetof (struct test_1, c) == test_1_offsets[0]);
  35. CHECK (offsetof (struct test_1, f) == test_1_offsets[1]);
  36. CHECK (offsetof (struct test_1, c2) == test_1_offsets[2]);
  37. CHECK (offsetof (struct test_1, i) == test_1_offsets[3]);
  38. return 0;
  39. }