while (1) vs. for ( ;; )

R

Richard Heathfield

Steven Kobes said:
Quoting Thad Smith:

Quoting Richard Heathfield:

I give up... what guarantee are you talking about?

Sorry for the late reply - I've been busy.

And another sorry, for of course it was a trick question. The guarantee we
have about the behaviour of this program, under any conforming
implementation, is that it (the program's behaviour) is undefined.
 
T

Tim Rentsch

Alexei A. Frounze said:
[snip]

IMO, the above may be warned as use of uninitialized variable.
And the actual problem maybe the mighty trap taking on trap representation
of uninitialized int.
If it wasn't for the last one, there would be no reason to warn at all on
either (a | !a) or (a & !a), because both would always evaluate to constant,
no matter what the (valid) values of a are...

If 'a' is of type 'int', the expression 'a | !a' can produce undefined
behavior even when it's guaranteed that 'a' has a valid value.
 
T

Tim Rentsch

Tim Rentsch said:
[snip]

If 'a' is of type 'int', the expression 'a | !a' can produce undefined
behavior even when it's guaranteed that 'a' has a valid value.

Sorry, I misspoke.
 
G

Giorgos Keramidas

Chris McDonald said:
I would suggest that both while(1) and for(;;) are potentially unclear
to a person (undergrad. student) seeing C for the first time
(while assuming they haven't seen Java or C++, either).

OK, I suggest that while(true) is *clearer*.

Maybe. Depending on what `true' is defined to be, though, it may be
less clear and/or buggy :)
 
A

Alexei A. Frounze

Tim Rentsch said:
Tim Rentsch said:
[snip]

If 'a' is of type 'int', the expression 'a | !a' can produce undefined
behavior even when it's guaranteed that 'a' has a valid value.

Sorry, I misspoke.

Do you mean by the above that I was right?
Or do you want to say it must have been || instead of |? But then again,
shouldn't !a be an int or should it be some special ("logical") kind of int?

Alex
 
T

Tim Rentsch

Alexei A. Frounze said:
Tim Rentsch said:
Tim Rentsch said:
[snip]

If 'a' is of type 'int', the expression 'a | !a' can produce undefined
behavior even when it's guaranteed that 'a' has a valid value.

Sorry, I misspoke.

Do you mean by the above that I was right?
Or do you want to say it must have been || instead of |? But then again,
shouldn't !a be an int or should it be some special ("logical") kind of int?

What I meant was that my brain must have wandered into a
region of space where the neutron flux density was too high,
and the errant reasoning that ensued led to a conclusion
that wasn't logically justified. In other words I retract
the statement, without meaning to have offered any further
opinion on the topic.

What I believe to be true, although I haven't checked this
belief as carefully as I would like, is that the expression

(s | !s) == (s ? s : 1) || (s | !s) == -1

must always evaluate to 1, with no possibility for undefined
behavior, if 's' is an int and has a valid value (ie, is not
a trap representation) in it before the expression is
evaluated. (Note: under some rather strange assumptions
about expression evaluation, I believe it's possible that
the value of the expression above might not be 1; however,
I believe there is no possibility for undefined behavior
even if those assumptions were true.)

So if what you were trying to say is implied by the
statement above, then Yes, I think you're right.

(Sorry not to be more specific, but your statement got lost
in one of the snippages.)
 

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,770
Messages
2,569,583
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top