Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fix sem_init testing.
[simgrid.git] / buildtools / Cmake / test_prog / prog_GRAS_CHECK_STRUCT_COMPACTION.c
1 /* Copyright (c) 2010. The SimGrid Team.
2  * All rights reserved.                                                     */
3
4 /* This program is free software; you can redistribute it and/or modify it
5  * under the terms of the license (GNU LGPL) which comes with this package. */
6
7 #include <sys/types.h>
8 #include <stddef.h>             /* offsetof() */
9 #include <stdio.h>
10
11 int main(void)
12 {
13
14   struct s0 {
15     char c0;
16     double d0;
17   };
18   struct s1 {
19     double d1;
20     int i1;
21     char c1;
22   };
23   struct s2 {
24     double d2;
25     int i2;
26     char c2[6];
27   };
28   struct s3 {
29     double d3;
30     int a3;
31     int b3;
32   };
33
34   int gras_struct_packed;
35   int gras_struct_compact;
36   int gras_array_straddle_struct;
37   int gras_compact_struct;
38
39   if (sizeof(struct s0) == sizeof(double) + sizeof(char)) {
40     gras_struct_packed = 1;
41   } else {
42     gras_struct_packed = 0;
43   }
44   if (offsetof(struct s1, c1) == sizeof(double) + sizeof(int)) {
45     gras_struct_compact = 1;
46   } else {
47     gras_struct_compact = 0;
48   }
49   if (offsetof(struct s2, c2) == sizeof(double) + sizeof(int)) {
50     gras_array_straddle_struct = 1;
51   } else {
52     gras_array_straddle_struct = 0;
53   }
54   if (offsetof(struct s3, b3) == sizeof(double) + sizeof(int)) {
55     gras_compact_struct = 1;
56   } else {
57     gras_compact_struct = 0;
58   }
59
60
61   if (gras_struct_packed == 0 && gras_struct_compact == 1)
62     printf("GRAS_STRUCT_COMPACT ");
63
64   if (gras_array_straddle_struct == 1)
65     printf("GRAS_ARRAY_STRADDLE_STRUCT ");
66
67   if (gras_compact_struct == 1)
68     printf("GRAS_COMPACT_STRUCT ");
69
70   return 1;
71
72 }