signed bit fields

Does anybody knows, Keil C compiler V7.xx supports bit fields with signed types or not?
The code always generated same as for unsigned types. This is compiler bug or feature? My code compiled with Keil C fails on MCU, but
works excellent on PC when compiled with gcc.

Example:

struct xxx {
signed y: 7;
};


struct xxx *s;
volatile int i;

i = s->y;
/* This operator does not extends y to i
with sign, instead all higher bits masked
with zeros */
; i = s->y;
MOV DPTR,#s?25158
MOVX A,@DPTR
MOV R3,A
INC DPTR
MOVX A,@DPTR
MOV R2,A
INC DPTR
MOVX A,@DPTR
MOV R1,A
LCALL ?C?ILDPTR
MOV R5,A
MOV R4,B
ANL A,#07FH
MOV R7,A
MOV DPTR,#i?25159
CLR A
MOVX @DPTR,A
INC DPTR
MOV A,R7
MOVX @DPTR,A


i=-2, s->y=i;
/* This operator again only masking
higher bits of i without carying of
sign bit */
; i=-2;
MOV DPTR,#i?25159
MOV A,#0FFH
MOVX @DPTR,A
INC DPTR
DEC A
MOVX @DPTR,A
; s->y=i;
MOV DPTR,#i?25159+01H
MOVX A,@DPTR
ANL A,#07FH
MOV R7,A
MOV A,R5
ANL A,#080H
MOV R5,A
MOV A,R4
MOV R6,A
MOV A,R5
ORL A,R7
MOV R7,A
MOV A,R6
MOV B,R7
LCALL ?C?ISTPTR

Parents
  • Bitfields are notoriously non-portable, and their implementation is often not efficient.

    What do you need to do with this bitfield that can't be done with conventional masks, etc?

    Search the knowledgebase - there are articles about some specific Gotchas! with bitfields in C51.
    Also check the C51 Manual.

    And try a search of this forum for previous discussions.

Reply
  • Bitfields are notoriously non-portable, and their implementation is often not efficient.

    What do you need to do with this bitfield that can't be done with conventional masks, etc?

    Search the knowledgebase - there are articles about some specific Gotchas! with bitfields in C51.
    Also check the C51 Manual.

    And try a search of this forum for previous discussions.

Children
More questions in this forum