Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.


CLR in union{struct{}} assignment

  • rudolf


       I am trying to assign values to a struct inside a union, and the asm code looks strange.
    If I dont assign all chars in a sequence, the chars that are not assigned will be cleared. Example:

    typedef union { // This compiler uses byte alignment! // maximum size is 8 bytes
                    unsigned char dat[4];
            struct {
                    unsigned char b3;
                    unsigned char b2;
                    unsigned char b1;
                    unsigned char b0;
                  } inbuffermod;

    inbuffermod buff;

    void main(void) {
        buff.b.b3=67; // others are cleared!
            buff.dat[buff.b.b0-1] = 0;

    will generate:

        MOVLW    0x43
        MOVWF    (_buff + 0)
    ;/home/sdcc-builder/build/sdcc-build/orig/sdcc/src/pic/gen.c:7685: size=2/4, offset=1, AOP_TYPE(res)=8
        CLRF    (_buff + 1)
    ;/home/sdcc-builder/build/sdcc-build/orig/sdcc/src/pic/gen.c:7685: size=1/4, offset=2, AOP_TYPE(res)=8
        CLRF    (_buff + 2)
    ;/home/sdcc-builder/build/sdcc-build/orig/sdcc/src/pic/gen.c:7685: size=0/4, offset=3, AOP_TYPE(res)=8
        CLRF    (_buff + 3)

    but actually it is a struct, not an union, I dont want to clear (_buff + 1), (_buff + 2) and (_buff + 3).
    Is it a bug or is it standart?
    does someone knows a workaround? I can send you a minimal code to reproduce the error.

    Thank you!

    SDCC : mcs51/gbz80/z80/avr/ds390/pic16/pic14/TININative/xa51/ds400/hc08 2.8.0 #5117 (Mar 23 2008) (UNIX)