Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
059941d8e32c40cf4f0bf59128d392ca6641a023
[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 {char c0; double d0;};
15 struct s1 {double d1; int i1; char c1;};
16 struct s2 {double d2; int i2; char c2[6];};
17 struct s3 {double d3; int a3; int b3;}; 
18
19 int gras_struct_packed;
20 int gras_struct_compact;
21 int gras_array_straddle_struct;
22 int gras_compact_struct;
23
24         if (sizeof(struct s0) == sizeof(double)+sizeof(char))
25         {
26                 gras_struct_packed=1;
27         }
28         else
29         {
30                 gras_struct_packed=0;
31         }
32         if (offsetof(struct s1,c1) == sizeof(double)+sizeof(int))
33         {
34                 gras_struct_compact=1;
35         }
36         else
37         {
38                 gras_struct_compact=0;
39         }
40         if (offsetof(struct s2,c2) == sizeof(double)+sizeof(int))
41         {
42                 gras_array_straddle_struct=1;
43         }
44         else
45         {
46                 gras_array_straddle_struct=0;
47         }
48         if (offsetof(struct s3,b3) == sizeof(double)+sizeof(int))
49         {
50                 gras_compact_struct=1;
51         }
52         else
53         {
54                 gras_compact_struct=0;
55         }
56
57
58         if(gras_struct_packed == 0 && gras_struct_compact == 1) printf("GRAS_STRUCT_COMPACT ");
59
60         if(gras_array_straddle_struct == 1) printf("GRAS_ARRAY_STRADDLE_STRUCT ");
61
62         if(gras_compact_struct == 1) printf("GRAS_COMPACT_STRUCT ");
63
64 return 1;
65
66 }