#285 Bitfields

closed-fixed
None
5
2013-05-25
2002-01-30
No

volatile struct
{
int b : 1;
int dummy: 7;
} bitfield;

bit b;
char c;
int i;
long l;

void foo (void)
{
bitfield.b = c;
bitfield.b = i;
bitfield.b = l;
}

; tc.c:14: bitfield.b = i;
mov a,_i
orl a,(_i + 1)
mov r2,a
mov r0,#_bitfield
mov b,r2
mov a,@r0
anl a,#0xfe
orl a,b
mov @r0,a

2 problems:

1.) all bits of bitfield can be changed, because
something like "anl a,#1" is missing.
2.) major problem: all compilers (Keil, IAR, gcc)
assign only the LSB to bitfield.b:
bitfield.b = i & 1;

AFAIK { bitfield.b = i ? 1 : 0; } is a bug.

{ b = i; } is a different issue. Keil and SDCC compile
it to { b = i ? 1 : 0; }, IAR to { b = i & 1; }

Discussion

  • Erik Petrich

    Erik Petrich - 2003-08-14

    Logged In: YES
    user_id=635249

    My latest CVS commits fix problems 1 & 2.

    However, { b = i; } brings to light some problems with the
    difference between a bit and a bit field of length 1. As far
    as I can tell, a bit appears to be a bit field whose storage
    was allocated to bit addressable memory. Thus sometimes
    (when they are stored elsewhere, for example) they are
    indistinguishable from a bit field, making the type
    conversions inconsistent. I'm still looking at this part.

     
  • Erik Petrich

    Erik Petrich - 2003-08-14

    Logged In: YES
    user_id=635249

    My latest CVS commits fix problems 1 & 2.

    However, { b = i; } brings to light some problems with the
    difference between a bit and a bit field of length 1. As far
    as I can tell, a bit appears to be a bit field whose storage
    was allocated to bit addressable memory. Thus sometimes
    (when they are stored elsewhere, for example) they are
    indistinguishable from a bit field, making the type
    conversions inconsistent. I'm still looking at this part.

     
  • Erik Petrich

    Erik Petrich - 2003-08-18

    Logged In: YES
    user_id=635249

    I believe this has been all resolved with my last commits.

    {bitfield.b = i;} resolves to {bitfield.b = i & 1;}
    {b = i;} resolves to {b = i ? 1 : 0;}

    A bit type also retains this behaviour when passed as a
    parameter
    (see bug #456966) even though the parameter is not allocated to
    bit memory.

     
  • Erik Petrich

    Erik Petrich - 2003-08-18
    • milestone: --> fixed
    • assigned_to: nobody --> epetrich
    • status: open --> closed-fixed
     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks