Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
09/08/06 00:16
Read: times


 
#123890 - Style
Responding to: ???'s previous message
Mark Buster said:
I think this is more readable and easier to make data specific changes to if nothing else.

It is.

Another way to make it more readable & maintainable is to use symbolic names instead of "magic numbers"; eg,
// Indexes for the byte positions in a Basic Set Frame
#define LEN       0
#define TYPE      1
#define CMD       2
#define NODE      3 /* (Target Node) */
#define COMMLEN   4 /* (Length of data specific payload within Frame) */
#define COMMCLASS 5
#define COMM      6
#define LASTKEY   7
#define TXOPT     8
#define FUNCID    9

char BasicSetFrame[10];

int  pos;          //position within array
char Length = 0xA; //Length of frame, excluding SOF and Checksum

BasicSetFrame[LEN       ] = Length;  
BasicSetFrame[TYPE      ] = 0x00;
BasicSetFrame[CMD       ] = 0x13;       // SendData
BasicSetFrame[NODE      ] = IconNodeID;
BasicSetFrame[COMMLEN   ] = 0x03;       
BasicSetFrame[COMMCLASS ] = 0x20;       // Basic
BasicSetFrame[COMM      ] = 0x01;       // Basic Set
BasicSetFrame[LASTKEY   ] = LastKey;    // Decoded Button Press/Release
BasicSetFrame[TXOPT     ] = 0x05;
BasicSetFrame[FUNCID    ] = 0x00;	

Note also how aligning comments, etc, makes it easier to read

List of 24 messages in thread
TopicAuthorDate
^= , Checksum, Problem            01/01/70 00:00      
   Have you tried a simulator?            01/01/70 00:00      
      well,            01/01/70 00:00      
      OK            01/01/70 00:00      
   volatile?            01/01/70 00:00      
      volatile            01/01/70 00:00      
         using ICE ?            01/01/70 00:00      
            update code (working) and clarification            01/01/70 00:00      
               Style            01/01/70 00:00      
               Think about your variable types            01/01/70 00:00      
                  Thanks            01/01/70 00:00      
                     Magic numbers            01/01/70 00:00      
                        but don't be "oversmart"            01/01/70 00:00      
                           example?            01/01/70 00:00      
                           advantages            01/01/70 00:00      
                              the most often forgotten quality guarantee            01/01/70 00:00      
                     so, use structures!            01/01/70 00:00      
                        padding            01/01/70 00:00      
                   and             01/01/70 00:00      
                     Actual Output            01/01/70 00:00      
                     C99            01/01/70 00:00      
                        making up your own            01/01/70 00:00      
                           Names            01/01/70 00:00      
                     FYI - C99 Exact- & Minimum-width types            01/01/70 00:00      

Back to Subject List