How to use reserved members of a struct



  • From header1.h

    typedef struct {
    
    	// Large number of fields snipped
    
    	short				reserved1;			// Used by DSI
    	long				reserved2;			// Ditto -- fence data
    	double				reserved3;			// Ditto -- RESERVED Value
    	short				reserved4;			// Ditto -- max alt refs built
    	short				reserved5;			// Ditto -- number of sig digits
    	long				reserved6;			// mine
    
    	// More fields snipped
    
    } subrec, *subptr;

    From header2.h:

    typedef struct {
    
    	// Large number of fields snipped
    
    	short		reserved1;		// Used by DSI
    	long		reserved2;		// Ditto -- fence data
    	double		reserved3;		// Ditto -- RESERVED Value
    	short		reserved4;		// Ditto -- max alt refs built
    	short		reserved5;		// Ditto -- number of sig digits
    	long		reserved6;		// mine
    } OBJECTSTRUCT;

    From header3.h

    // redefinition of the OBJECTSTRUCT reserve fields so they are more user friendly
    
    #define type_id			reserved1
    #define plus_fence_ref		reserved2
    #define value			reserved3
    #define max_alt_num		reserved4
    #define sig_digits		reserved5
    #define rows_columns		reserved6
    

    The names and types of the six "reserved" fields are the only things that the two structs have in common.



  • Using a compiler that doesn't support unions, so they use reserved structure members instead and then #define them? 

    Still, I can  think of several situations where #define'ing reservedX can cause some subtle bugs that could take hours to track down... So its still a WTF,



  • @Mole said:

    Using a compiler that doesn't support unions, so they use reserved structure members instead and then #define them?

    I don't see what unions have to do with anything...



  • As in, I've seen this kind of thing before: 
    typedef struct { // common record structure

    // Large number of fields snipped

    short reserved1; // Used by DSI
    long reserved2; // Ditto -- fence data
    double reserved3; // Ditto -- RESERVED Value
    short reserved4; // Ditto -- max alt refs built
    short reserved5; // Ditto -- number of sig digits
    long reserved6; // mine

    // More fields snipped

    } subrec, *subptr;
    // redefinition of structure as 'rectype'
    #define type_id			reserved1
    #define plus_fence_ref reserved2
    #define value reserved3
    #define max_alt_num reserved4
    #define sig_digits reserved5
    #define rows_columns reserved6
    // redefinition of structure as 'rectype2'
    #define type_id			reserved1
    #define foo_ref reserved2
    etc... so the same structure can handle many different formats. You can read from a file into a structure and then reference depending on the type_id of the first field.  


Log in to reply
 

Looks like your connection to What the Daily WTF? was lost, please wait while we try to reconnect.