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

about C my references are a bit unclear re this

by my references, I read that the below (x = n if no break) is true. However should that not be the case, and Keil can change it there is a great risk, thus I'd like another read on it.

a for loop

for ( x = 0 ; x < n ; x++)
{
  .......
  if (cond) break;
  .......
}
if (x = n)
{ // there was no break


can I count on x = n if 'cond' was never met and no break happened?

If that is not something that Keil can change, but standard, I can save a bunch of flags

Erik

Parents
  • The ISO C99 spec is probably a suspect source anyway, since Keil doesn't even claim C99 compatibility in the first place

    Quite certainly true for Erik's Keil compiler, i.e. C51. The ARM tools might very well support C99.

    and also because C99 introduces the ability to declare loop variables in the loop, a la C++

    Precisely. As far as standard C before C99 was concerned, Erik's original observation is correct, but C99's support for loop-scoped variables muddies that water.

    Otherwise you have to declare an extra variable just to record the termination value

    Not really. You just have to move the definition to a place before the for loop. Immediately before should do:

       int i = 0;
       for ( ; i < 20 ; i++) {
          /* some code */
       }
    

Reply
  • The ISO C99 spec is probably a suspect source anyway, since Keil doesn't even claim C99 compatibility in the first place

    Quite certainly true for Erik's Keil compiler, i.e. C51. The ARM tools might very well support C99.

    and also because C99 introduces the ability to declare loop variables in the loop, a la C++

    Precisely. As far as standard C before C99 was concerned, Erik's original observation is correct, but C99's support for loop-scoped variables muddies that water.

    Otherwise you have to declare an extra variable just to record the termination value

    Not really. You just have to move the definition to a place before the for loop. Immediately before should do:

       int i = 0;
       for ( ; i < 20 ; i++) {
          /* some code */
       }
    

Children
No data