Infinite loop

6.13 Control Statement Expressions

Moderators: misra-c, david ward

Locked
JonM
Posts: 8
Joined: Wed Apr 25, 2007 9:03 am
Location: Warwickshire

Infinite loop

Post by JonM » Wed Sep 12, 2007 2:29 pm

What is the preferred implementation of an infinite loop?

Code: Select all

for ( ; ; ) ...
or

Code: Select all

while (1 == 1) ...
or

something else?

Thanks in advance.

Jonathan

misra-c
Posts: 564
Joined: Thu Jan 05, 2006 1:11 pm

Post by misra-c » Wed Sep 26, 2007 3:19 pm

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

Code: Select all

/* deliberate infinite loop */
for ( ; ; )
{
   ...
}
---
Posted by and on behalf of
the MISRA C Working Group

JonM
Posts: 8
Joined: Wed Apr 25, 2007 9:03 am
Location: Warwickshire

Post by JonM » Thu Sep 27, 2007 3:00 pm

Yes I saw that it was allowed. Is while (1==1) also allowed? Which is preferred?

George Brown
Posts: 10
Joined: Fri Jul 13, 2007 1:13 pm

Post by George Brown » Wed Jan 09, 2008 4:11 pm

Hi Jon,

Looks like \"they\" said

Code: Select all

/* 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: Select all

/* deliberate infinite loop */ 
while(true) 
{ 
   ... 
}
George
Embeded Software developer since 85.

Locked

Return to “6.13 Control Statement Expressions”