Dear Friends: I never met the following definition before, would you help me to find out how they can define them like this?
#define ResetInfo(info) info.cmd = 0; info.status = MI_OK; info.irqSource = 0; info.nBytesSent = 0; info.nBytesToSend = 0; info.nBytesReceived = 0; info.nBitsReceived = 0; info.collPos = 0; typedef struct { unsigned char cmd; //!< command code char status; // communication status unsigned char nBytesSent; // how many bytes already sent unsigned char nBytesToSend; // how many bytes to send unsigned char nBytesReceived;// how many bytes received unsigned short nBitsReceived; // how many bits received unsigned char irqSource; // which interrupts have occured unsigned char collPos; // at which position occured a // collision } MfCmdInfo; static volatile MfCmdInfo MInfo; ResetInfo(MInfo);
what is the actual danger here? It is theoretically possible that padding bits/bytes have to be something *else* than zero, and that zeroing them yields a signalling representation. I.e. first time you try to use any of those zeroed values, the program could, theoretically, halt. To put it in more accessible terms: all-bits zero for an FP value could conceivably be a NaN.
OK, now I get you!
On the Keil toolchains (C51/C166/C251/CARM) memset with ZERO is a safe way to initialize a struct with 0. Reinhard