This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

About Structure Definition

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);

Thank you.

Parents
  • "There is no guarantee that all data types use all-bits-zero to represent zero."

    Ah yes, that's true.
    In the specific example posted, I s'pose we don't know that MI_OK is numerically zero.

    But I don't think that was Hans-Berhard's specific point:

    "in general, memset() is not a valid method of initializing any data structure containing larger-than-byte elements." (my emphasis).

    Apart from possibly unnecessary zeroing of padding bytes, what is the actual danger here?

Reply
  • "There is no guarantee that all data types use all-bits-zero to represent zero."

    Ah yes, that's true.
    In the specific example posted, I s'pose we don't know that MI_OK is numerically zero.

    But I don't think that was Hans-Berhard's specific point:

    "in general, memset() is not a valid method of initializing any data structure containing larger-than-byte elements." (my emphasis).

    Apart from possibly unnecessary zeroing of padding bytes, what is the actual danger here?

Children