Mostly Bollogs, I'm afraid

But occasionally, a glimmer of truth.
If you find one, please let me know.



Tuesday, 18 March 2014

Crapiler

I have a compiler which won't compile this. The error is at the bottom.  It's perfectly valid ANSI C, apart from possibly the undeclared array sizes (but it makes no difference if I declare those).

So, C folk, how do I address these without incurring the compilers wrath? I have six other compilers which accept this, but this one won't. The dog.

typedef struct {
    BYTE preamble;
    BYTE packsize[2];
    BYTE target;
} sPacketHeader;

typedef struct {
    BYTE size;
    BYTE Origin;
    BYTE module;
    BYTE version;
    BYTE sub;
} sDCUheader;

typedef struct {
    struct {
        BYTE ADH;
        BYTE ADL;
    } sAD[3];

    unsigned FAN_INITIATE : 1;
    unsigned CLOCK : 1;
    unsigned PLA16D : 1;
    unsigned OVERLOAD : 1;
    unsigned GROUP_FAULT_REPORT : 1;
    unsigned SHUTDOWN : 1;
    unsigned EXCESS_TEMP : 1;
    unsigned FILLER1 : 1;

    unsigned HOT_STANDBY : 1;
    unsigned EARTH_FAULT : 1;
    unsigned OVERRIDE : 1;
    unsigned ENGAGED : 1;
    unsigned LINE_FAULT : 1;
    unsigned AMP_FAULT : 1;
    unsigned MODE_D : 1;
    unsigned HIGH_TEMP : 1;

    // inhibit bits are inverted
    unsigned INHIBIT_AMP_FAULT : 1;
    unsigned INHIBIT_EXCESS_TEMP : 1;
    unsigned INHIBIT_EARTH_FAULT : 1;
    unsigned INHIBIT_EOL : 1;
    unsigned filler2 : 4;
} sAmpData;

typedef struct {
    unsigned ROTARY :4;
    unsigned SELECTED :4;
    unsigned PERMANENT :1;
    unsigned HEALTHY :1;
    unsigned MUX_ON :1;
    unsigned JUMPER :1;
    unsigned filler :4;
} sCageData;

typedef struct {
    sPacketHeader packetheader;
    sDCUheader DCUheader;
    struct {
        BYTE length;
        union {
            BYTE payload[1];
            struct sBits {
                BYTE version;
                sAmpData ampData;
            } bits;
        } u;
    } DCUdata;
    BYTE subcount;
    BYTE checksum[2];
} AmpIn;

typedef struct {
    sDCUheader DCUheader;
    struct {
        BYTE length;
        union {
            BYTE payload[1];
            struct sBits {
                BYTE version;
                sAmpData ampData;
                sCageData cageData;
            } bits;
        } u;
    } DCUdata;
    BYTE subcount;
} sAmpOut;

sAmpOut sao[2];


int main() {
sao[1].DCUdata.u.bits.cageData.ROTARY=1;

// error: unknown member "cageData" in sBits

}

2 comments:

Anonymous said...

Symbol table lookup bug. Rename one of the sBits structs.
What piece of shit compiler is it?

Anonymous said...

The compiler that barfed is correct - the ones that accepted are shit. Valid C++ namespacing isn't always valid C namespacing. C is retarded here, but you have to work with what you're given.