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

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
07/12/06 23:31
Read: times


 
#120135 - More Code Problems
Responding to: ???'s previous message
Satish said:
Is there is any thing wrong with code?


Rob Klein said:
Yes, it's uncommented and unformatted!


It also seems to be full of "magic numbers" - it is generally better to define symbolic constants with meaningful names; eg,
unsigned char TX_BUF[25]={"012345678901234567890123"}; 
unsigned char RX_BUF[25];

One might note that both buffer sizes are 25 - is that deliberate, or just coincidence?

If it's deliberate, you could make that much clearer by simply defining a single constant, and using it twice; eg,
#define BUFFER_SIZE 25
unsigned char tx_buf[BUFFER_SIZE]="012345678901234567890123"; 
unsigned char rx_buf[BUFFER_SIZE];

As well as making it clearer that the buffers are deliberately the same size, the code is easier to maintain - the size can be changed by simply updateing the #define in one place only, rather than having to search for all the occurrances of "25" (or even "24") and change them accordingly.

Note that it is conventional in 'C' to reserve ALL UPPERCASE names for #defines

List of 4 messages in thread
TopicAuthorDate
help needed for uart c8051f005            01/01/70 00:00      
   Code problems            01/01/70 00:00      
      More Code Problems            01/01/70 00:00      
         probelm solve            01/01/70 00:00      

Back to Subject List