what does "for( ; ; )" mean in C program

W

Walter Roberson

bobby said:
what does for( ; ; ) mean in C program

This is a loop.

Do no initializations.

Do not test any condition to see whether you should continue.

Do not do anything after the end of a loop before the beginning
of the next loop through.


In summary: for(;;) is another way of writing while (1)
which is an infinite loop (unless broken out of somewhere
in the middle.)
 
B

bobby

This is a loop.

Do no initializations.

Do not test any condition to see whether you should continue.

Do not do anything after the end of a loop before the beginning
of the next loop through.

In summary: for(;;) is another way of writing while (1)
which is an infinite loop (unless broken out of somewhere
in the middle.)

Thank a lot
 
T

Tomás Ó hÉilidhe

Ben Pfaff:
while() is not valid syntax. I think you mean that a while(1)
loop is equivalent to for(;;).


But the extra-paranoid don't use it coz they don't want 1 to be evaluted
upon every iteration ;-)
 
H

Harald van Dijk

Ben Pfaff:

But the extra-paranoid don't use it coz they don't want 1 to be evaluted
upon every iteration ;-)

Some people avoid using while(1) because they have to deal with broken
tools that give warnings for while(1) that they don't give for for(;;).
Splint is an example of this:

$ cat splint-is-weird.c
int main(void) {
while (1) {}
}
$ splint splint-is-weird.c
Splint 3.1.2 --- 03 Jan 2008

splint-is-weird.c: (in function main)
splint-is-weird.c:2:10: Test expression for while not boolean, type int: 1
Test expression type is not boolean or int. (Use -predboolint to inhibit
warning)

Finished checking --- 1 code warning

Personally, I'd rather get rid of such broken tools -- splint especially
considering I've dealt with perfectly legitimate C code causing assertion
failures in it -- but others may consider the tools useful enough to work
around their deficiencies.
 
M

Michal Nazarewicz

Harald van Dijk said:
Some people avoid using while(1) because they have to deal with broken
tools that give warnings for while(1) that they don't give for for(;;).

for(;;) is also one character shorter then while(1). :p
 
K

Keith Thompson

runner said:
#define ever (;;)

for ever

If your goal is to be cute, by all means go ahead and use that macro.

If your goal is to write understandable and maintainable C, please
don't.
 
R

runner

If your goal is to be cute, by all means go ahead and use that macro.

If your goal is to write understandable and maintainable C, please
don't.

I'm being cute, i don't need that macro. But it does its job in explaining
what happens when no expression is provided.

--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,217
Latest member
IRMNikole

Latest Threads

Top