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
  • I'd also probably use memset() instead of a whole series of assignments to 0.

    Given that there's non-atomic elements in that structure (i.e. anything else than char types), that'd be at least potentially dangerous coding. I'm reasonably sure this doesn't apply to C51, but please keep in mind that in general, memset() is not a valid method of initializing any data structure containing larger-than-byte elements.

Reply
  • I'd also probably use memset() instead of a whole series of assignments to 0.

    Given that there's non-atomic elements in that structure (i.e. anything else than char types), that'd be at least potentially dangerous coding. I'm reasonably sure this doesn't apply to C51, but please keep in mind that in general, memset() is not a valid method of initializing any data structure containing larger-than-byte elements.

Children