#1185 PIC16: undefined value written into union

closed-duplicate
nobody
5
2013-05-25
2006-08-12
Thorsten Klose
No

1)
-----------------------------------------------------
typedef union {
struct {
unsigned ALL:8;
};
struct {
unsigned RUN:1;
unsigned PAUSE:1;
unsigned START_REQ:1;
unsigned STOP_REQ:1;
unsigned CONT_REQ:1;
};
} mclock_state_t;

mclock_state_t mclock_state;

void MCLOCK_Init()
{
mclock_state.ALL = 0;
}

void main()
{
MCLOCK_Init();
}
-----------------------------------------------------

2) sdcc -S -mpic16 -p18F452 main.c

3) SDCC :
mcs51/gbz80/z80/avr/ds390/pic16/pic14/TININative/xa51/ds400/hc08
2.6.0 #4309 (Jul 28 2006) (MINGW32)

4)
generated assembly code:
-----------------------------------------------------
S_main__MCLOCK_Init code
_MCLOCK_Init:
; .line 19; main.c void MCLOCK_Init()
MOVFF FSR2L, POSTDEC1
MOVFF FSR1L, FSR2L
BANKSEL _mclock_state
; .line 21; main.c mclock_state.ALL = 0;
MOVWF _mclock_state, B
MOVFF PREINC1, FSR2L
RETURN
-----------------------------------------------------

WREG is not initialized, therefore an undefined value
will be written into _mclock_state

This C code was working with SDCC 2.5.0

Discussion

  • Maarten Brock
    Maarten Brock
    2006-08-12

    • milestone: --> known_bugs
    • status: open --> closed-duplicate