🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

1 total messages Started by Jeremy Greene Wed, 27 Nov 1996 00:00
bit field problem
#6103
Author: Jeremy Greene
Date: Wed, 27 Nov 1996 00:00
51 lines
1577 bytes

It appears the compiler does not access a bit field with the correct
type in all cases. Specifically, a char bit field is being accessed as
a long. I understand that bit fields are quite compiler dependent, but
this is a bit extreme.

We're using:
  Reading specs from /usr/global/lib/gcc-lib/sparc-sun-solaris2.4/
            2.7.2.1/specs
  gcc version 2.7.2.1

It's a completely vanilla compiler build.

Here's a very simple sample program which will bus-error on a sparc:

struct  Bits
{
   /* if there's a bit field:
    */
   unsigned char y:4;

   /* it fails with this (although other primitive types can exist)
    */
   struct {
      int bar;
   } broken;
};


int main()
{
   char data[30];
   register struct Bits *bits;

   bits = &data[2];

   /* If running on a 'must-align' cpu like a sparc, it
    * bus-errors here. It's doing an int-32 fetch instead of a char.
    */
   bits->y = 5;

   return 0;
}

The compile statement I used is:

   gcc -g test.c -o test

Thanks for any help,
 Jeremy
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads