L4Re/departure

Annotated tests/dstest_align.cc

618:7123a7307a82
8 months ago Paul Boddie Introduced some debugging output control.
paul@428 1
#include <stdio.h>
paul@428 2
#include <stdint.h>
paul@455 3
#include <systypes/format.h>
paul@428 4
paul@458 5
#define FMTsize "%" pFMTsize "d"
paul@455 6
#define FMT32x "%" pFMT32 "x"
paul@455 7
#define FMT64x "%" pFMT64 "x"
paul@434 8
#define OFFSET(obj, mem) ((char *) &(obj)->mem - (char *) obj)
paul@434 9
paul@428 10
struct A
paul@428 11
{
paul@428 12
  uint32_t a;
paul@428 13
  uint64_t b;
paul@428 14
  uint64_t c;
paul@428 15
} __attribute__ ((packed));
paul@428 16
paul@428 17
struct B
paul@428 18
{
paul@428 19
  uint32_t a;
paul@428 20
  uint64_t b;
paul@428 21
  uint64_t c;
paul@428 22
};
paul@428 23
paul@428 24
struct C
paul@428 25
{
paul@428 26
  uint32_t a;
paul@428 27
  uint32_t b;
paul@428 28
  uint64_t c;
paul@428 29
};
paul@428 30
paul@428 31
int main(int argc, char *argv[])
paul@428 32
{
paul@455 33
  (void) argc; (void) argv;
paul@455 34
paul@428 35
  struct A a = {1, 2, 3};
paul@428 36
  struct B b = {1, 2, 3};
paul@428 37
  struct C c = {1, 2, 3};
paul@428 38
  uint32_t m[6] = {1, 2, 3, 4, 5, 6};
paul@428 39
  struct A *ma = (struct A *) m;
paul@428 40
  struct A *ma1 = (struct A *) (m + 1);
paul@428 41
paul@458 42
  printf("a.a @ offset " FMTsize " = " FMT32x "\n", OFFSET(&a, a), a.a);
paul@458 43
  printf("a.b @ offset " FMTsize " = " FMT64x "\n", OFFSET(&a, b), a.b);
paul@458 44
  printf("a.c @ offset " FMTsize " = " FMT64x "\n\n", OFFSET(&a, c), a.c);
paul@458 45
  printf("b.a @ offset " FMTsize " = " FMT32x "\n", OFFSET(&b, a), b.a);
paul@458 46
  printf("b.b @ offset " FMTsize " = " FMT64x "\n", OFFSET(&b, b), b.b);
paul@458 47
  printf("b.c @ offset " FMTsize " = " FMT64x "\n\n", OFFSET(&b, c), b.c);
paul@458 48
  printf("c.a @ offset " FMTsize " = " FMT32x "\n", OFFSET(&c, a), c.a);
paul@458 49
  printf("c.b @ offset " FMTsize " = " FMT32x "\n", OFFSET(&c, b), c.b);
paul@458 50
  printf("c.c @ offset " FMTsize " = " FMT64x "\n\n", OFFSET(&c, c), c.c);
paul@458 51
  printf("ma.a @ offset " FMTsize " = " FMT32x "\n", OFFSET(ma, a), ma->a);
paul@458 52
  printf("ma.b @ offset " FMTsize " = " FMT64x "\n", OFFSET(ma, b), ma->b);
paul@458 53
  printf("ma.c @ offset " FMTsize " = " FMT64x "\n\n", OFFSET(ma, c), ma->c);
paul@458 54
  printf("ma1.a @ offset " FMTsize " = " FMT32x "\n", OFFSET(ma1, a), ma1->a);
paul@458 55
  printf("ma1.b @ offset " FMTsize " = " FMT64x "\n", OFFSET(ma1, b), ma1->b);
paul@458 56
  printf("ma1.c @ offset " FMTsize " = " FMT64x "\n\n", OFFSET(ma1, c), ma1->c);
paul@428 57
paul@428 58
  return 0;
paul@428 59
}