1 /* { dg-do run { target { pcc_bitfield_type_matters || default_packed } } } */
2 
3 /* Check bitfields and non-bitfields are aligned & sized similarly.
4 
5    Copyright (C) 2002 Free Software Foundation Inc
6    Contributed by Nathan Sidwell <nathan@codesourcery.com>
7 */
8 
9 #include <limits.h>
10 #include <stdio.h>
11 
12 static int fail;
13 
14 #define CHECK1(N, T) do { \
15   typedef struct Field_##N { char c; T f; } Field_##N; \
16   typedef struct BitField_##N { char c; T f : sizeof (T) * CHAR_BIT; } BitField_##N; \
17   if (sizeof (Field_##N) != sizeof (BitField_##N)) { \
18     fail = 1; printf ("sizeof %s failed\n", #T); \
19   } \
20   if (__alignof__ (Field_##N) != __alignof__ (BitField_##N)) { \
21     fail = 1; printf ("__alignof__ %s failed\n", #T); \
22   } \
23 } while (0)
24 
25 #define CHECK(N, T) do { \
26   CHECK1(N, T); \
27   CHECK1 (s##N, signed T); \
28   CHECK1 (u##N, unsigned T); \
29 } while (0)
30 
main()31 int main ()
32 {
33 
34   CHECK (c, char);
35   CHECK (s, short);
36   CHECK (i, int);
37   CHECK (l, long);
38   CHECK (ll, long long);
39 
40   return fail;
41 }
42