andrew@motto.UUCP (Andrew Walduck) (10/22/90)
>how about these: > >#define ever (;;) >#define nothing ; > >Then you get > >for ever > { > ... > } Is this really defined to loop forever?? Does ANSI guarantee this behaviour? Just to be safe I'd define ever like: #define ever(;1;) Just to make the behaviour predictable. >----------------- >Jeffrey Hutzelman >America Online: JeffreyH11 >Internet/BITNET:jh4o+@andrew.cmu.edu, jhutz@drycas.club.cc.cmu.edu, > jh4o@cmuccvma >>> Apple // Forever!!! << << Commodore 64 forever!!! >> ;-) Andrew Walduck andrew@motto.UUCP -- Motorola Canada
henry@zoo.toronto.edu (Henry Spencer) (10/23/90)
In article <250@motto.UUCP> andrew@motto.UUCP (Andrew Walduck) writes: >>#define ever (;;) >>for ever >> { >> ... >Is this really defined to loop forever?? Does ANSI guarantee this >behaviour? It has been a property of C since the start that "for (;;) <statement>" is an infinite loop. ANSI, naturally, has reaffirmed this. Incidentally, "#define ever (;;)" is a habit that most C programmers grow out of. It adds nothing to the readability and tends to confuse auxiliary tools like paragraphers and cross-referencers. -- The type syntax for C is essentially | Henry Spencer at U of Toronto Zoology unparsable. --Rob Pike | henry@zoo.toronto.edu utzoo!henry
jh4o+@andrew.cmu.edu (Jeffrey T. Hutzelman) (10/25/90)
andrew@motto.UUCP (Andrew Walduck) writes: >>#define ever (;;) >>#define nothing ; >> >>Then you get >> >>for ever >> { >> ... >> } > Is this really defined to loop forever?? Does ANSI guarantee this > behaviour? > Just to be safe I'd define ever like: > #define ever(;1;) > Just to make the behaviour predictable. A couple things. As has been pointed out to me (and I kind of knew already), the #define ever is not actually very useful. However, I use for(;;) all the time in place of while(1) with no problem. And yes, I believe that it is defined that the loop will loop forever if the condition is not given. Some one back me up on this, or tell me I;m wrong. ----------------- Jeffrey Hutzelman America Online: JeffreyH11 Internet/BITNET:jh4o+@andrew.cmu.edu, jhutz@drycas.club.cc.cmu.edu, jh4o@cmuccvma >> Apple // Forever!!! <<
pfalstad@phoenix.Princeton.EDU (Paul John Falstad) (10/26/90)
In article <wb9lIa600awBI61Go2@andrew.cmu.edu> jh4o+@andrew.cmu.edu (Jeffrey T. Hutzelman) writes: >However, I use for(;;) all the time in place of while(1) with no >problem. And yes, I believe that it is defined that the loop will loop >forever if the condition is not given. Some one back me up on this, or >tell me I;m wrong. K&R2, p224: "A missing second expression [in a for] makes the implied test equivalent to testing a non-zero constant." >>> Apple // Forever!!! << What a terrifying thought. :-) -- Paul Falstad, pfalstad@phoenix.princeton.edu PLink:HYPNOS GEnie:P.FALSTAD "Your attention please. Would the owner of the Baader-Meinhof shoulder-bag which has just exploded outside the terminal please pick up the white courtesy phone."
jh4o+@andrew.cmu.edu (Jeffrey T. Hutzelman) (10/27/90)
Thanks for the info.
-----------------
Jeffrey Hutzelman
America Online: JeffreyH11
Internet/BITNET:jh4o+@andrew.cmu.edu, jhutz@drycas.club.cc.cmu.edu,
jh4o@cmuccvma
>> Apple // Forever!!! <<