This is the mail archive of the
gcc-prs@gcc.gnu.org
mailing list for the GCC project.
bootstrap/3188: I define bit fields in a long long, union the long long, and print.
- To: gcc-gnats at gcc dot gnu dot org
- Subject: bootstrap/3188: I define bit fields in a long long, union the long long, and print.
- From: khundzinski-pdr-ca at worldnet dot att dot net
- Date: 14 Jun 2001 22:43:03 -0000
- Cc: real_timexxx at sourceware dot cygnus dot com
- Reply-To: khundzinski-pdr-ca at worldnet dot att dot net
>Number: 3188
>Category: bootstrap
>Synopsis: I define bit fields in a long long, union the long long, and print.
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: unassigned
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Thu Jun 14 15:46:01 PDT 2001
>Closed-Date:
>Last-Modified:
>Originator: Kenneth Hundzinski
>Release: unknown-1.0
>Organization:
>Environment:
QNX
>Description:
I print the long long variable in hex as a long long, as 32 bit integer, as short int, and as char to check out the bit fields. The long long hex print prints 0's in the first word.
>How-To-Repeat:
compile and run
>Fix:
don't know
>Release-Note:
>Audit-Trail:
>Unformatted:
----gnatsweb-attachment----
Content-Type: text/plain; name="bt_test64.c"
Content-Disposition: inline; filename="bt_test64.c"
#include <stdio.h>
int main()
{
struct lw_bit_test
{
unsigned long long w0_b_0_7 :8;
unsigned long long w0_b_8_14 :7;
unsigned long long w0_b_15_20 :6;
unsigned long long w0_b_21_25 :5;
unsigned long long w0_b_26_29 :4;
unsigned long long w0_b_30_31 :2;
unsigned long long w0_b_32_40 :9;
unsigned long long w0_b_41_50 :10;
unsigned long long w0_b_51_61 :11;
unsigned long long w0_b_62_63 :2;
};
struct w_bit_test
{
unsigned short s0_b_0_3 :4;
unsigned short s0_b_4_6 :3;
unsigned short s0_b_7_8 :2;
unsigned short s0_b_9 :1;
unsigned short s0_b_10_15 :6;
unsigned int s1_b_0_5 :6;
unsigned int s1_b_6 :1;
unsigned int s1_b_7_8 :2;
unsigned int s1_b_9_11 :3;
unsigned int s1_b_12_15 :4;
unsigned short s2_b_0_3 :4;
unsigned short s2_b_4_6 :3;
unsigned short s2_b_7_8 :2;
unsigned short s2_b_9 :1;
unsigned short s2_b_10_15 :6;
unsigned int s3_b_0_5 :6;
unsigned int s3_b_6 :1;
unsigned int s3_b_7_8 :2;
unsigned int s3_b_9_11 :3;
unsigned int s3_b_12_15 :4;
};
union
{
struct lw_bit_test lbt;
unsigned long long uli;
unsigned short s_a [4];
unsigned int i_a [2];
unsigned char ch_a [8];
} ul;
//union
//{
// struct s_bit_test sbt;
// unsigned short sa [4];
//} us;
ul.lbt.w0_b_0_7 = 8;
ul.lbt.w0_b_8_14 = 7;
ul.lbt.w0_b_15_20 = 6;
ul.lbt.w0_b_21_25 = 5;
ul.lbt.w0_b_26_29 = 4;
ul.lbt.w0_b_30_31 = 2;
ul.lbt.w0_b_32_40 = 9;
ul.lbt.w0_b_41_50 = 10;
ul.lbt.w0_b_51_61 = 11;
ul.lbt.w0_b_62_63 = 2;
//
fprintf(stdout, "union a=%p l=%d \n", &ul, sizeof(ul) );
fprintf (stdout, "64 bit a=%p l=%d %016x \n", &ul.uli, sizeof(ul.uli), (long long) ul.uli );
//------
fprintf (stdout, "32 bit 0,1 a=%p %p l=%d %d %08x %08x \n",
&ul.i_a[0], &ul.i_a[1], sizeof(ul.i_a), sizeof(ul.i_a),ul.i_a [0], ul.i_a [1] );
//---------------------------------
fprintf (stdout, "s wd a=%p %p %p %p l=%d %d %d %d \n",
&ul.s_a [0], &ul.s_a [1], &ul.s_a [2], &ul.s_a [3],
sizeof (ul.s_a [0]), sizeof (ul.s_a [1]), sizeof (ul.s_a [2]), sizeof (ul.s_a [3] ));
fprintf (stdout, " s word 0,1,2,3 %04x %04x %04x %04x \n",
ul.s_a [0], ul.s_a [1], ul.s_a [2], ul.s_a [3]);
//---------------------------------
fprintf(stdout, " char a= %p %p %p %p %p %p %p %p \n",
&ul.ch_a[0],&ul.ch_a[1],&ul.ch_a[2],&ul.ch_a[3],
&ul.ch_a[4],&ul.ch_a[5],&ul.ch_a[6],&ul.ch_a[7] );
fprintf(stdout, " char l= %d %d %d %d %d %d %d %d \n",
sizeof(ul.ch_a[0]), sizeof(ul.ch_a[1]), sizeof(ul.ch_a[2]), sizeof(ul.ch_a[3]),
sizeof(ul.ch_a[4]), sizeof(ul.ch_a[5]), sizeof(ul.ch_a[6]), sizeof(ul.ch_a[7]) );
fprintf(stdout, " char %02x %02x %02x %02x %02x %02x %02x %02x ",
ul.ch_a[0],ul.ch_a[1],ul.ch_a[2],ul.ch_a[3],
ul.ch_a[4],ul.ch_a[5],ul.ch_a[6],ul.ch_a[7] );
// fprintf (stdout, " short word 2,3 %04x %04x %04x %04x %04x %04x %04x %04x \n",
// ul.s_a [2], ul.s_a [3] );
// fprintf (stdout, " long word %04x %04x %04x %04x %04x %04x %04x %04x
fprintf (stdout, "End of Job\n");
}