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 ??????????

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

    Err, you are. Did you actually understand what this code does?

  • 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?

  • Look carefully at the value of your variable 'i'.
    What are you expecting it to do?
    Is it doing what you expect it to do?

    And, how do you expect it to exit the loop (hint: check the method of loop exit).

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

    I suspect it does not even compile since C does not have a "> =" operator.

  • thanks for replying my question. the results were interesting. some of you even found the right answer.

  • Are you the twin brother (or a clone) of "Teper LAK"?

    See here:

    http://www.keil.com/forum/20966

  • But the open issue here is what is "the right answer".

    An even more interesting question here is why you think a web forum should be a syntax checker? A compiler is great at handling such problems - and someone who do want answers about syntax errors would normally post the relevant part of the source code, and the relevant messages from the compiler.

    And it is a known fact that lots of people do not copy their code, but retype it, when posting here. So their questions are not related to the new syntax errors they introduce in the posting process. And in this case, the code had more than one syntax error.

    But few developers would consider syntax errors as "bug" - which is the thread title. A bug is when a program don't do what we expected.

    And the interesting loop did contain a construct that may - or may not - be seen as a bug. Or at least indicate that the program don't end up doing very much. The intention of that loop obviously very much controls the need for another loop to stop the program from exiting.

  • very interesting. all useful information for my research.

  • well jameel, the only information glaring from this thread is that you do not know what you are doing (you really don't, dude) and are too proud to admit it...be less of a macho, it will allow you to learn something !

  • you do not know what you are doing

    I think it is more likely that you guys gave him the answers to his home work assignment, he is performing an experiment to see what kind of responses he would get or he is just messing with you.