🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.gcc.bug
Article #6103

bit field problem

#6103
From: 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
Technical Details
Message-ID: <3e1a8eeb46ff73f53187186b87190031@wretched.mailer.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 113d02,766ce23cf280fcf1,start
X-Google-Attributes: gid113d02,public
From: jeremy@xedia.com (Jeremy Greene)
Subject: bit field problem
Date: 1996/11/27
Message-ID: <3e1a8eeb46ff73f53187186b87190031@wretched.mailer.com>
X-Deja-AN: 201163350
sender: bug-gcc-request@prep.ai.mit.edu
x-gateway: wendy-fate.uu.net from bug-gcc to gnu.gcc.bug; Wed, 27 Nov 1996 22:26:19 EST
return-path: <gnulists-usenet-ownrr@prep.ai.mit.edu>
newsgroups: gnu.gcc.bug