Yours truly recently had a VERY weird issue concerning system prefs. The structure given below worked well while in main memory, but saving/restoring it via the Preference API led to total fuxation of all values below the logging struct:
typedef struct{
UInt16 autoOff:1;
UInt16 timestamp: 2;
UInt16 flashscreen: 1;
UInt16 autoConnect: 1;
UInt16 pingpong: 3;
UInt16 bell: 1;
UInt16 wrap: 1;
UInt16 reserved: 6;
FontID font;
} OptionsType;
//LEAVE the __attribute__((packed)) in place - the prefs comnpile without it,
//but CHANGE WHEN BEEING SAVED AND THEREBY CREATE A LOGIC BOMB
typedef struct
{
char server[52]; // 50+1 Not sure on this one
char nick[20]; // 16+1
char realname[31];
}default_struct;
typedef struct
{
Boolean enabled;
Boolean logPvt;
Boolean filePerChannel;
char volname[40];
char parent[256];
}logging_struct;
typedef struct
{
Boolean alertnetdrop;
Boolean lowbatshutdown;
}bgm_struct;
typedef struct{
UInt16 appNetRefNum;
NetSocketRef socketRef;
NetIPAddr addr;
UInt16 port;
UInt32 bugged_last;
//These prefs are used by the network routines themselves
//and will one day replace the global variables
char server[51]; // 50+1 Not sure on this one
char channel[31]; // 30+1
char nick[17]; // 16+1
char pass[17]; // 16+1
OptionsType display;
bgm_struct background;
//These are UI ONLY variables and are NOT intended for any other use
//except as defaults for new ServMgmt entries => padding is 4by
default_struct defaults;
logging_struct logging;
Int32 sample;
} myIRCPreferenceType;
The reason for this issue has to do with weird padding issues - GCC adds extra bytes that do nothing, but are needed for some reason or another.
However, GCC supports a special command that disables the padding algorithm temporarily for a structure of choice. Adding these to offending structure definitions fixed the problem:
typedef struct
{
char server[52]; // 50+1 Not sure on this one
char nick[20]; // 16+1
char realname[31];
}default_struct __attribute__((packed));
I am at a loss at why this works - but the program now works flawlessly.
Does anyone of you have any ideas as to what’s happening here?