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);
Since I never met this kind of definition before, it is wired to me..
#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;
"I think ResetInfo is a function for resetting MInfo structure, right?" Wrong. It is a Macro - not a function! This is plain, pure vanilla, bog-standard use of #define - see any standard 'C' textbook. As Drew said, it'd probably be easier just to use memset. And, stylistically, a true function would probably be better than a macro.