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

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
01/08/08 21:37
Read: times


 
Msg Score: +1
 +1 Good Answer/Helpful
#149155 - Bad indenting trap!
Responding to: ???'s previous message
John Myers said:
Your pointer assignment "PtrRx = &CompDataRx[0];" and "SerialInit(9600);" are within the main loop.

The code will continually reset 'PtrRx'.

This is an example of where poor style is not just a matter of taste, but has actually misled you, me and a few others!

Your code, as posted, was:
void main()
{
	while(1){
	PtrRx = &CompDataRx[0];		// start address in the array
	
	CompAddress1 = P1;
	CompAddress2 = CompAddress1 + 0x80;
	CompAddress3 = CompAddress1 + 0x90;
	HwDelay(20);

	// etc...

The problem would have been a lot more obvious id you'd indented it as:
void main()
{
    while(1){
	PtrRx = &CompDataRx[0];		// start address in the array
	
	CompAddress1 = P1;
	CompAddress2 = CompAddress1 + 0x80;
	CompAddress3 = CompAddress1 + 0x90;
	HwDelay(20);

	// etc...

You also need to make up your mind where you will put that opening brace: either on a line of its own or or the end of a line - but pick one and be consistent!

List of 26 messages in thread
TopicAuthorDate
Serial Problem            01/01/70 00:00      
   Can you post more information ?            01/01/70 00:00      
      more information            01/01/70 00:00      
         Too much information!            01/01/70 00:00      
         Some advice            01/01/70 00:00      
         while loop            01/01/70 00:00      
            Bad indenting trap!            01/01/70 00:00      
               Andu, Andy, how dare you ..            01/01/70 00:00      
            I don't think that's the problem.            01/01/70 00:00      
               you're right            01/01/70 00:00      
                  So, have you got it working yet?            01/01/70 00:00      
                     can't receive the 16 bytes            01/01/70 00:00      
                        Have you dealt with the atomicity issues ?            01/01/70 00:00      
                        Debugging            01/01/70 00:00      
                           details            01/01/70 00:00      
   Misleading comment            01/01/70 00:00      
      I too dislike the placement, even worse it is WRON            01/01/70 00:00      
   RI and TI are not mutually exclusive            01/01/70 00:00      
      ... but this is not a cause it will not work...            01/01/70 00:00      
         Yes...            01/01/70 00:00      
   Here is a sample code that is working ...            01/01/70 00:00      
      ... and here for the right processor            01/01/70 00:00      
         Wheel reinvention is -            01/01/70 00:00      
         I have a doubt about that KEIL code.            01/01/70 00:00      
            The Question is what do you want to loose?            01/01/70 00:00      
               No - I was just wondering the hardware            01/01/70 00:00      

Back to Subject List