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

important bug


void main ( void );
{
 /************************************
 *                                   *
 *          Define a variable i      *
 *                                   *
 ************************************/

 unsigned int i;

 /************************************
 *                                   *
 *          Start of loop            *
 *                                   *
 ************************************/

  for ( i = 10 ; i > = 0 ; i = i - 1 )

  {

 /************************************
 *                                   *
 *          Add one to i             *
 *                                   *
 ************************************/

    i=i+1;

  }

  what is wrong ??????????

Parents
  • Nothing is wrong with the program except that you seem to have lost the closing brace in the post.

    A more relevant question is: What does this program do. And what did _you_ expect it to do?

    Because it does very much look like this program does something totally different from what you originally intended.

    Another thing - a program that doesn't affect LEDs or prints messages on a serial port is very hard to observe. In this case, your only way of seeing what it does (besides simulating it in your head) is to run it in a debugger. If you do, it would be easy to see what is actually happening and compare with what you expected. So have you tried to debug the program? Or have you just started the program and then waited for something magical to happen?

    Another thing - how do you know the difference between a program that runs some internal magic code and then ends, or a program that never ends? If a program lit a LED when it started and unlit the LED just before ending, then you could at least look at the LED and try to figure out if the program is running or not.

    Yet another thing - let's say that your for loop will actually end - where do you think your program will end up then? Back to a command-line prompt? Or back to a graphical desktop? An embedded processor normally don't have any graphical desktop or a command-line interface. So is it even meaningful for the majority of embedded programs to actually end? Who decides what happens if an embedded program do end? What promises have Keil given to you about what will happen if your program would actually end?

Reply
  • Nothing is wrong with the program except that you seem to have lost the closing brace in the post.

    A more relevant question is: What does this program do. And what did _you_ expect it to do?

    Because it does very much look like this program does something totally different from what you originally intended.

    Another thing - a program that doesn't affect LEDs or prints messages on a serial port is very hard to observe. In this case, your only way of seeing what it does (besides simulating it in your head) is to run it in a debugger. If you do, it would be easy to see what is actually happening and compare with what you expected. So have you tried to debug the program? Or have you just started the program and then waited for something magical to happen?

    Another thing - how do you know the difference between a program that runs some internal magic code and then ends, or a program that never ends? If a program lit a LED when it started and unlit the LED just before ending, then you could at least look at the LED and try to figure out if the program is running or not.

    Yet another thing - let's say that your for loop will actually end - where do you think your program will end up then? Back to a command-line prompt? Or back to a graphical desktop? An embedded processor normally don't have any graphical desktop or a command-line interface. So is it even meaningful for the majority of embedded programs to actually end? Who decides what happens if an embedded program do end? What promises have Keil given to you about what will happen if your program would actually end?

Children