GCC Bugzilla – Attachment 29119 Details for
Bug 52991
[6/7/8 Regression] attribute packed broken on mingw32?
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
Testcase for bitfield and type-packing
msbit_tests.c (text/plain), 2.32 KB, created by
Kai Tietz
on 2013-01-09 12:30:50 UTC
(
hide
)
Description:
Testcase for bitfield and type-packing
Filename:
MIME Type:
Creator:
Kai Tietz
Created:
2013-01-09 12:30:50 UTC
Size:
2.32 KB
patch
obsolete
>#include <stdio.h> > >static int diff_ptr (const void *p1, const void *p2) >{ > const char *c1 = (const char *) p1; > const char *c2 = (const char *) p2; > return (int) (c2 - c1); >} > >static int check_ptr (const void *base, const void *off, int expect) >{ > int v = diff_ptr (base, off); > if (v == expect) > return 1; > printf (" expect %d, but we got %d", expect, v); > return 0; >} > >/* First packing */ >#pragma pack(1) >struct sP1_1 { > char a; > char b; > short c; >}; > >struct sP1_2 { > char a; > unsigned char b; > short c; >}; > >struct sP1_3 { > char a : 1; > unsigned char b : 1; > short c; >}; > >struct sP1_4 { > char a : 1; > char b : 1; > short c; >}; > >#pragma pack(2) >struct sP2_1 { > char a; > char b; > short c; >}; >struct sP2_2 { > char a; > unsigned char b; > short c; >}; >struct sP2_4 { > char a : 1; > char b : 1; > short c; >}; > >#pragma pack(4) >struct sP4_1 { > char a; > char b; > short c; >}; >struct sP4_2 { > char a; > unsigned char b; > short c; >}; >struct sP4_4 { > char a : 1; > char b : 1; > short c; >}; > >#pragma pack(8) >struct sP8_1 { > char a; > char b; > short c; >}; >struct sP8_2 { > char a; > unsigned char b; > short c; >}; >struct sP8_4 { > char a : 1; > char b : 1; > short c; >}; > >#define chk(STR, FIELD, EXPECT) \ > { struct STR a##STR; \ > if (!check_ptr (&a##STR, &a##STR.FIELD, EXPECT)) \ > printf (" %s (%s - .) == %d: failed\n", "a" #STR, #FIELD, EXPECT); \ > } > >#define siz(STR, SZ) \ > if (sizeof (struct STR) != SZ) \ > printf ("sizeof(%s): is %d and not equal to expected %d\n", #STR, (int) sizeof (struct STR), SZ); \ > >int main() >{ > chk(sP1_1, b, 1); > chk(sP1_1, c, 2); > siz(sP1_1, 4); > chk(sP1_2, b, 1); > chk(sP1_2, c, 2); > siz(sP1_2, 4); > chk(sP1_3, c, 1); > siz(sP1_3, 3); > > chk(sP2_1, b, 1); > chk(sP2_1, c, 2); > siz(sP2_1, 4); > chk(sP2_2, b, 1); > chk(sP2_2, c, 2); > siz(sP2_2, 4); > > chk(sP4_1, b, 1); > chk(sP4_1, c, 2); > siz(sP4_1, 4); > chk(sP4_2, b, 1); > chk(sP4_2, c, 2); > siz(sP4_2, 4); > > chk(sP8_1, b, 1); > chk(sP8_1, c, 2); > siz(sP8_1, 4); > chk(sP8_2, b, 1); > chk(sP8_2, c, 2); > siz(sP8_2, 4); > > chk(sP1_4, c, 1); > siz(sP1_4, 3); > chk(sP2_4, c, 2); > siz(sP2_4, 4); > chk(sP4_4, c, 2); > siz(sP4_4, 4); > chk(sP8_4, c, 2); > siz(sP8_4, 4); > return 0; >}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 52991
: 29119 |
29121
|
29122
|
43522