Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Infinite loop
#1
What is the preferred implementation of an infinite loop?

Code:
for ( ; ; ) ...

or

Code:
while (1 == 1) ...

or

something else?

Thanks in advance.

Jonathan
#2
In the TC, we allow the for loop example with all three expressions being empty for a deliberate infinite loop.

Code:
/* deliberate infinite loop */
for ( ; ; )
{
   ...
}
Posted by and on behalf of the MISRA C Working Group
#3
Yes I saw that it was allowed. Is while (1==1) also allowed? Which is preferred?
#4
Hi Jon,

Looks like \"they\" said

Code:
/* deliberate infinite loop */
for ( ; ; )
{
   ...
}

was the allowed form is infinite loops. Given one way to write them, there is no need for alternatives.

I was taught Pascal back in the early 80's, and would like to write this in the following form. C99 defines a \"boolean\" type, so MISRA-C3 could be different!
Code:
/* deliberate infinite loop */
while(true)
{
   ...
}

George


Forum Jump:


Users browsing this thread: 1 Guest(s)