[comp.std.c] for

karl@haddock.ima.isc.com (Karl Heuer) (05/25/90)

In article <5897@buengc.BU.EDU> bph@buengc.bu.edu (Blair P. Houghton) writes:
>If I were to write a compiler under K&R1 and provide a no-optimization mode,
>`for(;;)' would be an unconditional branch and `while(1)' would compare 1 to
>0 and then branch-if-unequal, because that's what the syntax implies.

I suppose you would also compile `if (x==y)' into code that compares x against
y, sets a temporary to either 0 or 1, and then compares that value against
zero, right?

Your statements are vacuously true, because according to your definitions,
nobody has ever written a "non-optimizing" compiler.

Karl W. Z. Heuer (karl@ima.ima.isc.com or harvard!ima!karl), The Walking Lint

diamond@tkou02.enet.dec.com (diamond@tkovoa) (05/25/90)

How do we know if they're a draw?  All you people who are arguing
which is better:  one of you code an infinite loop with for(;;)
and one of you code an infinite loop with while(1).  When they
finish, wake me (from the dead) and tell me.

The rest of us can go RTFS.  TFS says that both forms are legal.
This is the only answer that belongs in ThisFNewsgroup.

Some of us will even use optimizers when we can get our hands on them.
Though this does not belong in ThisFNewsgroup.

-- 
Norman Diamond, Nihon DEC     diamond@tkou02.enet.dec.com
Proposed group comp.networks.load-reduction:  send your "yes" vote to /dev/null.

exspes@gdr.bath.ac.uk (P E Smee) (05/25/90)

In article <12971@smoke.BRL.MIL> gwyn@smoke.BRL.MIL (Doug Gwyn) writes:
>If a compiler is going
>to generate a useless comparison, it is in fact more likely
>to do so for while(1) than for for(;;).

One benefit of 'for(;;)' over 'while (1)' which I haven't seen
mentioned is that most (in my experience) versions of 'lint' will
cheerfully accept 'for(;;)' without comment, while giving a 'constant
in conditional' warning for 'while(1)'.

You could plausibly argue that lint is broken and should recognize this
use of while as a special case.  You could also plausibly argue that C
should have an explicit 'do forever' construct.  However, neither of
these seem to be true, and I have no control over them; I can control
my code and like it to be lint-free (or as near as possible -- 'There
are some things you just cant get lint to shut up about' from lint(1)).

(Yeah, I know how to hide things from lint.  I don't like to do that,
though, for fear that I'll make a REAL error which it would have
caught, somewhere where it can't see it because I've hidden it.)

-- 
Paul Smee, Computing Service, University of Bristol, Bristol BS8 1UD, UK
 P.Smee@bristol.ac.uk - ..!uunet!ukc!bsmail!p.smee - Tel +44 272 303132

aipdc@castle.ed.ac.uk (Paul D. Crowley) (05/25/90)

I agree: this thread properly belongs in alt.religion.computers.
-- 
\/ o\ Paul Crowley aipdc@uk.ac.ed.castle
/\__/ "Trust me, I know what I'm doing" - Sledge Hammer

jsdy@hadron.COM (Joseph S. D. Yao) (05/25/90)

I just lied to 'rn'.  The following, like >75% of what preceded it,
isn't really worth sending or reading, but I thought I'd have my say.

When I was a beginning programmer, I thought the following was cute, so
I used it all over:
	#define ever	(;;)
	...
		for ever {
			...
		}

For that matter, I also define'd:
	#define until(x)	while (!(x))
	#define unless(x)	if (!(x))
to answer people who said "it doesn't have an "UNTIL" keyword, so what
good is it?"

Also, if our universe of discourse IS ENGLISH, then while(1) makes no
sense, because after the subordinate conjuction "while", one expects a
predicate, not a noun or noun phrase.  IN C, however, we all know that
predicates eventually evaluate to the-equivalent-of 1 or 0 ... but I
still teach people that, if they're going to do this kind of thing,
they should define TRUE and use while (TRUE) instead, it makes more
"intuitive sense", whatever that means (different for each of our
intuitions).

NOW, AS I SAID, ALL THIS MAKES NO DIFFERENCE WHATSOEVER.  It has been
shown that while(1) [or, better, while (TRUE)] and for (;;) [or, worse,
for ever] are logically equivalent by the definitions in both K&R and
X3J11.  The purposes of coding a program are (1) to communicate to the
computer what you intend for it to do, and (2) to communicate to other
people working on the same program (now or later) what you intend for
the computer to do.  [The latter is necessary, otherwise we'd compile
programs and throw the source away.  I HOPE you don't do that!]  BOTH
of these constructs do that.  Which is preferable is largely a cultural
thing.

On the other hand, I still prefer for (;;) ...		;-)

	Joe Yao				jsdy@hadron.COM
	( jsdy%hadron.COM@{uunet.UU.NET,decuac.DEC.COM} )
	arc,arinc,att,avatar,blkcat,cos,decuac,\
	dtix,ecogong,grebyn,inco,insight,kcwc,  \
	lepton,lsw,netex,netxcom,phw5,research,  >!hadron!jsdy
	rlgvax,seismo,sms,smsdpg,sundc,telenet, /
	uunet				       /
(Last I counted ...)

steve@taumet.COM (Stephen Clamage) (05/25/90)

In article <Z4O3P:2@xds13.ferranti.com> peter@ficc.ferranti.com (Peter da Silva) writes:
>... [this would mean that]
>the compiler can legally generate any code it likes for anything, so long
>as the semantics match the abstract machine. The compiler is permitted
>to generate any code it likes ...

Yup.  That's exactly what the ANSI standard says.  The standard makes
heavy use of the "as-if" rule for this reason.  It doesn't tell the
compiler implementor how to do the job, only what the result must be.
As in your hyperbolic example, a conforming compiler could send mail
to Dennis Ritchie (or to Bob Hope, for that matter) to get a value for
an expression whose semantics are undefined.
-- 

Steve Clamage, TauMetric Corp, steve@taumet.com

bph@buengc.BU.EDU (Blair P. Houghton) (05/26/90)

In article <Z4O3P:2@xds13.ferranti.com> peter@ficc.ferranti.com (Peter da Silva) writes:
>In article <5879@buengc.BU.EDU> bph@buengc.bu.edu (Blair P. Houghton) writes:
>> "The semantic descriptions in this standard describe the behavior
>> of an abstract machine in which issues of optimization are irrelevant."
>> (ANSI X3.159-1989, Sec. 2.1.2.3, pp. 8, ll. 29-30)
>
>I don't believe that is an operative statement. The quote you gave means
>the compiler can legally generate any code it likes for anything, so long
>as the semantics match the abstract machine. The compiler is permitted
>to generate any code it likes, including code that calls "sendmail" to
>mail a message to Dennis Ritchie asking him which way he thinks the test
>should go today.

When did I say otherwise?

				--Blair
				  "Are you paying attention?"

bph@buengc.BU.EDU (Blair P. Houghton) (05/26/90)

In article <3381@auspex.auspex.com> guy@auspex.auspex.com (Guy Harris) writes:
>>It's more logical.
>
>Some agree, some don't.  Who cares?  *I* certainly don't; I'll continue
>to use "for (;;)", because I'm used to it.

Good for you.  I probably will, too.  I just won't explain
it as anything other than a curiosity.

>>Before, an implementor that claimed their compiler did _no_
>>optimization could still turn `for(;;)' into an
>>unconditional branch, whereas `while(1)' was still forced
>>to compare-1-to-0-and-branch-if-not-equal.
>
>And somebody could then throw K&R at them, since the "for(...;...;...)
>is equivalent to <while construct>" stuff was in there, too.

Ayup.  They'd be optimizing without being asked to, but then,
they'd say "so what's K&R?  We wrote ours by altering Whitesmith's.".

>>An implementor that claimed to have a non-optimizing mode
>>on an ANSI-conforming compiler which then generated
>>different object code for the two constructs would be
>>committing fraud.  You can prove that and make it stick.
>
>With a bald statement like "you can prove that and make it stick", I'd
>almost be tempted to call your bluff and start selling a version of,
>say, GCC that *does* generate stupid code for "while(1)" while claiming
>it's ANSI-compliant, and watch you *try* to prove it.

It requires a stricter definition of "non-optimizing" than
it seems most people carry around with them.  They certainly
don't see it the way I do.

And I don't believe a word GNU says.  Nope.  Not one.

>Much though you may not like it, and much though you may think
>otherwise, the ANSI C standard just says how a C implementation (which
>might not generate code at all - consider an interpretive implementation
>that, stupid though it may seem, scans source and interprets it on the
>fly, without even generating some internal code); it does *not* dictate
>whether it generates the "best" code for some construct, nor even
>whether it generates the *same* code for equivalent constructs - as
>shown by, well, err, umm,

Here we go:

	for(;;) statement

	while(1) statement

	label: statement if(1) goto label;

are all the same; exactly the same, when translated into object code
without thinking about it.  You could contend that the third is
my invention, but the standard says the first two are identical.
I'd expect a compiler with no heuristics in it to prove me right.

Add optimization, and make it good, and it all becomes

	label: statement goto label;

>>"The semantic descriptions in this standard describe the behavior
>>of an abstract machine in which issues of optimization are irrelevant."
>>(ANSI X3.159-1989, Sec. 2.1.2.3, pp. 8, ll. 29-30)
>
>to quote an earlier disputant here.

Looks familiar.  Like Flaubert.

I didn't say the standard specified optimization.  I said the
implementor did, or rather, the implementor specified a _lack_
of it.  Then it went and optimized.

				--Blair
				  "I wanna clean bout.  No butting,
				   biting, or rabbit punching.  Best
				   two out of three hypothetical
				   situations wins.  Now go back
				   to your corners and come out
				   coding."

bph@buengc.BU.EDU (Blair P. Houghton) (05/26/90)

In article <1990May24.231054.22349@mozart.amd.com> tim@amd.com (Tim Olson) writes:
>K&R *DID* say this -- read the reference manual section about the For
>statement (9.6):
>
>	"Any or all of the expressions may be dropped.  A missing
>	expression-2 makes the implied while clause equivalent to
>	while(1); ..."

Oops.  My bad.  So whose compiler was it that did this?

				--Blair
				  "Grumble."

bph@buengc.BU.EDU (Blair P. Houghton) (05/26/90)

In article <12986@smoke.BRL.MIL> gwyn@smoke.BRL.MIL (Doug Gwyn) writes:
>In article <5897@buengc.BU.EDU> bph@buengc.bu.edu (Blair P. Houghton) writes:
>>1 certainly is "logical", as long as it's a nonzero
>>constant expression in C.
>
>"true" is logical.  "1" has to be explained as a special quirk of C.

As is done long before you get around to presenting `while'
and `for'.

>>You're implying that X3J11 could well have
>>left that sentence entirely out of the standard.
>
>No, I'm not; it was necessary to give meaning to the empty
>conditional clause in the "for" construct.  This says nothing
>about code generation, though.

At least you got that right.

>Note that the standard
>does not address issues of optimization, just requirements for
>conformance.

I never said it did.  I was the one who posted the sentence
where it explicitly abrogates that scope.

>I hope nobody has been
>misled by your misreading of the standard.

How altruistic of you.  Maybe we can get back to braces.

				--Blair
				  "Any compiler that optimizes
				   without my permission can
				   just stay in the box."

bph@buengc.BU.EDU (Blair P. Houghton) (05/26/90)

In article <16725@haddock.ima.isc.com> karl@haddock.ima.isc.com (Karl Heuer) writes:
>In article <5897@buengc.BU.EDU> bph@buengc.bu.edu (Blair P. Houghton) writes:
>>If I were to write a compiler under K&R1 and provide a no-optimization mode,
>>`for(;;)' would be an unconditional branch and `while(1)' would compare 1 to
>>0 and then branch-if-unequal, because that's what the syntax implies.
>
>I suppose you would also compile `if (x==y)' into code that compares x against
>y, sets a temporary to either 0 or 1, and then compares that value against
>zero, right?

Yes.  Then I'd compile it with a `-O' flag and the computer
wouldn't even have to load x and y.  It would _know_ they're
unequal just by smelling them.

>Your statements are vacuously true, because according to your definitions,
>nobody has ever written a "non-optimizing" compiler.

Probably.  Everyone wants to be helpful.

				--Blair
				  "Gilligan, If you wanna help, don't help."
				  -The Skipper

bph@buengc.BU.EDU (Blair P. Houghton) (05/26/90)

In article <1730@tkou02.enet.dec.com> diamond@tkou02.enet.dec.com (diamond@tkovoa) writes:
>The rest of us can go RTFS.  TFS says that both forms are legal.
>This is the only answer that belongs in ThisFNewsgroup.

Yeah, probably; but, I wish people had just sent me nice
letters saying "I see what you mean but I'll stick
with `for(;;)' anyway."

				--Blair
				  "The standard doesn't define
				   experts, either."

msb@sq.sq.com (Mark Brader) (05/26/90)

> > 1 certainly is "logical" ...
> "true" is logical.  "1" has to be explained as a special quirk of C.

Either "while(1)" or "while(TRUE)" requires, if not explanation, at least
a moment's thought on first encounter, because the reader has to think
about which way the degenerate test goes.  What better way to express the
absence of a test than by omitting the test from the statement?

(That C allows "for(;;)" and not also "while()" is presumably a historical
accident.  "while()" looks like a function call, but so does "while(x)".)

But if you think "while(1)" is more readable, well, you write it that way.
Just like brace styles, it's not worth fussing about.

-- 
Mark Brader			"It's simply a matter of style, and while there
SoftQuad Inc., Toronto		 are many wrong styles, there really isn't any
utzoo!sq!msb, msb@sq.com	 one right style."	-- Ray Butterworth

This article is in the public domain.

aipdc@castle.ed.ac.uk (Paul D. Crowley) (05/26/90)

In article <12986@smoke.BRL.MIL> gwyn@smoke.BRL.MIL (Doug Gwyn) writes:
>"true" is logical.  "1" has to be explained as a special quirk of C.

bph@buengc.bu.edu (Blair P. Houghton) sez in <5907@buengc.BU.EDU>
>As is done long before you get around to presenting `while'
>and `for'.

Well, not necessarily.   In fact, it would surprise me if by the time
you were presenting "for" you'd told people that integers were used to
represent boolean values.  Most people at that level of programming only
have the vaguest idea what a boolean value is anyway. "3<4" people can
cope with;  "3<4 == TRUE" is for mathematicians. "3<4 != 0" is abtruse.

Peeve: why doesn't C have a type "boolean" built in? It seems natural,
and I'm sure there's some compiler somewhere that could use it to
improve executables.

-- 
\/ o\ Paul Crowley aipdc@uk.ac.ed.castle
/\__/ "Trust me, I know what I'm doing" - Sledge Hammer

gwyn@smoke.BRL.MIL (Doug Gwyn) (05/26/90)

In article <5906@buengc.BU.EDU> bph@buengc.bu.edu (Blair P. Houghton) writes:
-In article <1990May24.231054.22349@mozart.amd.com> tim@amd.com (Tim Olson) writes:
->	"Any or all of the expressions may be dropped.  A missing
->	expression-2 makes the implied while clause equivalent to
->	while(1); ..."
-Oops.  My bad.  So whose compiler was it that did this?

Everybody's!  You don't seem to understand the difference between a
language specification and code generation.

gwyn@smoke.BRL.MIL (Doug Gwyn) (05/26/90)

In article <4232@castle.ed.ac.uk> aipdc@castle.ed.ac.uk (Paul D. Crowley) writes:
>Peeve: why doesn't C have a type "boolean" built in? It seems natural,
>and I'm sure there's some compiler somewhere that could use it to
>improve executables.

I think the only performance improvement one might expect would be the
possibility of allocating smaller objects to hold type "boolean".  This
would be really handy on architectures that efficiently support bit arrays.
(However, the lack of access to these from high-level languages has been
one of the factors that has kept them from being widely implemented.)

As I have mentioned before in comp.lang.c, practically all my applications
#include <std.h>, where std.h is configured once per porting environment
and mostly consists of macro definitions.  Among other things it says
	typedef int	bool;		/* Boolean data */
	#define 	false	0
	#define 	true	1
which I use consistently, exactly as though these were keywords and as
though C enforced a strict distinction between Boolean and integral types.
E.g.
	if ( p != NULL )
not
	if ( p )
I find that this leads to more reliable code, since minor slipups in
such things stand out like a sore thumb when I look at the code.

guy@auspex.auspex.com (Guy Harris) (05/27/90)

>Ayup.  They'd be optimizing without being asked to,

So what?

>	for(;;) statement
>
>	while(1) statement
>
>	label: statement if(1) goto label;
>
>are all the same; exactly the same, when translated into object code
>without thinking about it.  You could contend that the third is
>my invention, but the standard says the first two are identical.

The standard does *NOT* say, in any way, shape, or form, that they are
"exactly the same, when translated into object code without thinking
about it".  (The standard doesn't even say that an implementation
necessarily translates them into object code!)  It just says that they
have to *act* the same.  How the compiler arranges that that happen is
*not* X3.159-1989's business.

>I didn't say the standard specified optimization.

Well, if you didn't say anything about what the standard said, why are
you saying it *here*?  As several people have noted, the standard does
not dictate, *one way or the other*, whether "for(;;)" and "while(1)"
have to generate the exact same object code; all it says is that the
object code generated, assuming object code is generated at all, has to
provide the same semantics for both constructs.

>I said the implementor did, or rather, the implementor specified a _lack_
>of it.  Then it went and optimized.

"Optimization" is in the eye of the beholder.  Perhaps that's why the
standard doesn't tend to talk about it?

*I* don't demand that a compiler, when no "optimization" is specified,
generate code by the most naive algorithm possible, i.e. "without
thinking about it".  If you do, that's your choice.  For better or
worse, plenty of other people, I suspect, don't demand it either.

mfriedma@oracle.com (Michael Friedman) (05/27/90)

In article <5879@buengc.BU.EDU> bph@buengc.bu.edu (Blair P. Houghton) writes:
>In article <12955@smoke.BRL.MIL> gwyn@smoke.BRL.MIL (Doug Gwyn) writes:
>>In article <5876@buengc.BU.EDU> bph@buengc.bu.edu (Blair P. Houghton) writes:
>>-This means that now, assuming that the compiler chooses 1 as
>>-the "nonzero constant,"
>>-	for (;;) statement
>>-and
>>-	while (1) statement

>>First of all, there are experienced C programmers (myself among them)
>>who do not think that "while(1)" is in ANY way preferable to "for(;;)".
>>People who learned Pascal before C seem to think so, though.

>It's more logical.  So sue me.  `for(;;)' is idiomatic
>and has to be explained, sometimes twice, to new programmers.

Perhaps, on the other hand I, at least, find it unesthetic - while(1)
implies a test.  I don't want to do a test.   I just want to do an
infinite loop.  for(;;) seems to imply that pretty well.

>(I.e., and we can move this to alt.flame if you like,
>despite the timelessness of your ego you're gonna die long
>before C does, and not everyone needs to cling to "the old
>ways."  The standard also remaindered `=-' forevermore; do
>you want it back to provide compatibility with the "Hello,
>world!!!!" program you wrote back in 1979?)

Note that =- was not widely used.  You'll find for(;;) in tons of
code.  One of the mandates fo the standards committee was to
standardize the language as it exists, not to modify it in order to
satisfy various people.  In particular, they were not supposed to
break existing code.

>>Secondly, I don't know why you think the standard changes anything
>>whatsoever in the way that compilers must treat these constructs.
>>It doesn't.  They mean EXACTLY what they have always meant, and
>>EXACTLY the same code can be generated for them as before the standard.

>"Can" is not "will," and "must" is not "may."

>Before, an implementor that claimed their compiler did _no_
>optimization could still turn `for(;;)' into an
>unconditional branch, whereas `while(1)' was still forced
>to compare-1-to-0-and-branch-if-not-equal.  (No, nobody
>cared, but one would have been right to write an SPR if one
>found out it wasn't the case.)  The obvious optimization
>(possibly through a `-O' option) is to turn `while(1)' into
>an unconditional branch, just like `for(;;)' was always.

>Now, the standard has made it clear that without any
>optimization BOTH constructs will become compare-and-
>branch, and with or without optimization there has to be
>some point where the compilation acts as if `for(;;)' had
>been written `for(;1;)', which is to say (since the std is
>explicit on this; ANSI X3.159-1989, Sec. 3.6.5.3, pp. 79,
>ll. 31-39), as if it had been written `while(1)'.

>"The semantic descriptions in this standard describe the behavior
>of an abstract machine in which issues of optimization are irrelevant."
>(ANSI X3.159-1989, Sec. 2.1.2.3, pp. 8, ll. 29-30)

>An implementor that claimed to have a non-optimizing mode
>on an ANSI-conforming compiler which then generated
>different object code for the two constructs would be
>committing fraud.  You can prove that and make it stick.

No you can't.  I can just imagine you walking up to a compiler writer.

"You said that you don't optimize, but your compiler turns while(1)
into a compare and branch and for(;;) into a jmp.  That's fraud!!!"

"Huh?"

"You optimized when you said you wouldn't"

"So you got somehting for free.  File an enhancement request if this
matters to you."

"OK.  Enhancement request:  Please change your compiler so it
generates a compare and branch statement when it hits for(;;)"

Why do I think that that enhancement request wuld get a very low priority?


--
The passing of Marxism-Leninism first from China and then from the
Soviet Union will mean its death as a living ideology ... .  For while
there may be some isolated true believers left in places like Managua,
Pyongyang, or Cambridge, MA ...   - Francis Fukuyama

peter@ficc.ferranti.com (Peter da Silva) (05/27/90)

In article <5904@buengc.BU.EDU> bph@buengc.bu.edu (Blair P. Houghton) writes:
> In article <Z4O3P:2@xds13.ferranti.com> peter@ficc.ferranti.com (Peter da Silva) writes:
> >I don't believe that is an operative statement. The quote you gave means
> >the compiler can legally generate any code it likes for anything, so long
> >as the semantics match the abstract machine.

> When did I say otherwise?

When you said the standard requires the compiler generate identical code
for !while(1)! and !for(;;)!.
-- 
`-_-' Peter da Silva. +1 713 274 5180.  <peter@ficc.ferranti.com>
 'U`  Have you hugged your wolf today?  <peter@sugar.hackercorp.com>
@FIN  Dirty words: Zhghnyyl erphefvir vayvar shapgvbaf.

tkacik@rphroy.UUCP (Tom Tkacik) (05/28/90)

In article <5905@buengc.BU.EDU> bph@buengc.bu.edu (Blair P. Houghton) writes:
>It requires a stricter definition of "non-optimizing" than
>it seems most people carry around with them.  They certainly
>don't see it the way I do.

>Here we go:

>	for(;;) statement

>	while(1) statement

>	label: statement if(1) goto label;

>are all the same; exactly the same, when translated into object code
>without thinking about it.  You could contend that the third is
>my invention, but the standard says the first two are identical.
>I'd expect a compiler with no heuristics in it to prove me right.

>Add optimization, and make it good, and it all becomes

>	label: statement goto label;

>>>"The semantic descriptions in this standard describe the behavior
>>>of an abstract machine in which issues of optimization are irrelevant."
>>>(ANSI X3.159-1989, Sec. 2.1.2.3, pp. 8, ll. 29-30)
>
>I didn't say the standard specified optimization.  I said the
>implementor did, or rather, the implementor specified a _lack_
>of it.  Then it went and optimized.

Not turning for(;;) into while(1) is not an optimization.  I have not read the
standard, (am I still allowed to make a comment in forum:-), 
but from the massive amounts of discussion going on, it appears to
say that  for(;;) should act like while(1).

This is a semantic issue.  For(;;) should ACT exactly like while(1).
It does not seem be say that they should be the same, just act the same.
Therefore, a non-optimizing compiler could generate a loop and branch
for for(;;), because it is easier to do, knowing that this is semantically
the same as while(1), and not be doing any optimization that Blair claims
has just occured.

No internal form of while(1) was generated and optimized away.
It was never there to start with.  The standard does not say it has
to be, as long as the semantics are the same (which they are).
The compiler gave for(;;) the most basic definition, the semantics of while(1),
and generated stupid code, loop and branch.

Can we get on to something more enlightening than when is
legally a non-optimization?

When I feel the need to add something, things must surely have degenerated :-).
-- 
Tom Tkacik			GM Research Labs,   Warren MI  48090
Work phone: (313)986-1442	uunet!edsews!rphroy!megatron!tkacik
"I'm president of the United States, and I'm not going to eat anymore broccoli."
						--- George Bush

ok@goanna.cs.rmit.oz.au (Richard A. O'Keefe) (05/28/90)

In article <5897@buengc.BU.EDU>, bph@buengc.BU.EDU (Blair P. Houghton) writes:
> I just wanted to know
> whether _nobody_ was going to unobfuscate their coding
> style now that they know the dubious, increased efficiency
> of their `for(;;)' is now codified to be nil.

> I, for one, will encourage `while(1)' among new C
> programmers, because the increase in efficiency now comes
> from allowing maintainers to have a slightly lesser
> understanding of the history of C and still be able to
> understand this code.

Er, _what_ increase in efficiency?  I'm the kind of person who from time
to time takes the trouble to peek at the .s files produced by compilers
and see if they can be tweaked a bit.  I even figured out how to make a
compiler generate the 680x0 'DBRA' instruction once; highly non-obvious.
I've never yet been able to detect a significant difference between
for (;;) and while (1).

I loathe and detest while (1) because it's obfuscatory.
The thing is, a skilled programmer uses a while (..) statement because
that's the way it fell out of his preconditions, postconditions,
invariant, and so on.  You use 'while' to express "here after this
keyword is all the information you need about when the loop stops."
The only polite term I can think of for systematically violating this
conversational maxim is "non-Gricean".  As a sheerly practical matter,
it is virtually always a typo with extremely serious consequences if
the control expression in a while (...) or do while (...) is constant.
Having programming tools that warn about such blunders is _very_
useful.  And it would _not_ be a good idea to make them shut up about
the special cases while (1) and do while (1), that 1 could be the
result of a macro expansion.

For me, for (;;) loops are different.  They're what you write when you
have a loop that doesn't fall naturally into the while (..) pattern.
The character sequence (;;) has, I believe, no other use in C.  It's a
very clear signal "no, it _wasn't_ a mistake, I really _did_ mean to
put the real loop control somewhere else."

In fact, I would welcome a "lint" option that reported 'break' or
'continue' statements having a while (..) or do while (..) statement
as scope as being likely errors.  (Seriously!  If I were ever in a
position to recommend the purchase of one C checker or compiler over
another, having such an _option_ would influence my decision.)

> In a pinch, it will be one question
> *not* asked by someone coming from a Pascal background.

Um, I've recently had a lot more contact with people from a Pascal
background than I really wanted.  Quickly now, what's wrong with this:

	program main;
	    var i: integer;
	    procedure p(n: integer);
		begin
		    for i := 1 to n do write(' ');
		    writeln(i);
		end;
	    begin
		p(10);
	    end.

(I count three violations of the Pascal Standard.)  I've had people
from a Pascal background ask me "what's a pointer?"

> If, however, I were to write a conforming compiler and
> provide a no-optimization mode, both would compare 1 to 0
> before branching, because that's what the syntax implies.

But there is no way that a standard-conforming program can detect
whether there is a comparison there or not.

If one is going to engage in such micro-exegesis, one might pay careful
attention to the fact that the quoted section standard does _not_ say
that for (x;;y) is equivalent to for (x;1;y) but to for (x;c;y) for
*some* non-zero integer constant.  Is there anything to stop a
conforming C compiler from behaving as if the constant were 137, and
"optimising" both for (;;) and while (137), but not while (1)?
If so, what exactly?

> 				  "Have you ever even heard of
> 				   'the law of least surprise?'"

I have, but when I see people write while (1), I really wonder about _them_...

-- 
"A 7th class of programs, correct in every way, is believed to exist by a
few computer scientists.  However, no example could be found to include here."

bph@buengc.BU.EDU (Blair P. Houghton) (05/29/90)

In article <13001@smoke.BRL.MIL> gwyn@smoke.BRL.MIL (Doug Gwyn) writes:
>In article <5906@buengc.BU.EDU> bph@buengc.bu.edu (Blair P. Houghton) writes:
>-In article <1990May24.231054.22349@mozart.amd.com> tim@amd.com (Tim Olson) writes:
>->	"Any or all of the expressions may be dropped.  A missing
>->	expression-2 makes the implied while clause equivalent to
>->	while(1); ..."
>-Oops.  My bad.  So whose compiler was it that did this?
>
>Everybody's!  You don't seem to understand the difference between a
>language specification and code generation.

Doug, doug, doug.  Yes, I do.  Now if you wouldn't mind getting
off your desk and putting down the lamp and looking at what my
original article said, you'd see why you're making an utter ass
of yourself, and splashing excrement all over this group doing it.

				--Blair
				  "Sheesh."

bph@buengc.BU.EDU (Blair P. Houghton) (05/29/90)

In article <3398@auspex.auspex.com> guy@auspex.auspex.com (Guy Harris) writes:
Because in article <5879@buengc.BU.EDU> I said, in my own words, precisely:
>>	for(;;) statement
>>
>>	while(1) statement
>>
>>	label: statement if(1) goto label;
>>
>>are all the same; exactly the same, when translated into object code
>>without thinking about it.  You could contend that the third is
>>my invention, but the standard says the first two are identical.
>
>The standard does *NOT* say, in any way, shape, or form, that they are
>"exactly the same, when translated into object code without thinking
>about it".

That's it.

If one more person puts words in my mouth without my
permission, I'm going to fucking ram my fucking terminal
up their fucking groin.

	I NEVER SAID IT DID, YOU OBSTREPEROUS FUCKING ASSHOLE!!!

Have you and Doug been sucking pills out of the same prescription
of Stupidity?  Where the hell do you get the idea that I say that
ANSI X3.159-1989 says how to generate code?

				--Blair
				  "Do you comprehend, or do
				   words just roll across your
				   eyes like the CRT displays
				   on the spacesuit helmet face-
				   shields in 2001?"

bph@buengc.BU.EDU (Blair P. Houghton) (05/29/90)

In article <0:P3-A6@ggpc2.ferranti.com> peter@ficc.ferranti.com (Peter da Silva) writes:
>In article <5904@buengc.BU.EDU> bph@buengc.bu.edu (Blair P. Houghton) writes:
>> In article <Z4O3P:2@xds13.ferranti.com> peter@ficc.ferranti.com (Peter da Silva) writes:
>> >I don't believe that is an operative statement. The quote you gave means
>> >the compiler can legally generate any code it likes for anything, so long
>> >as the semantics match the abstract machine.
>
>> When did I say otherwise?
>
>When you said the standard requires the compiler generate identical code
>for !while(1)! and !for(;;)!.

You're lucky I got it all out of my system flaming at Doug 'n' Guy,
the Freak Brothers of comp.std.c.

I did not say the standard requires a compiler to generate
code in any particular way.  I said that a compiler that
the implementor claimed to be matching the standard's model
of a hypothetical machine would, in fact, generate
identical code for !while(1)!  and !for(;;)!.

I think that's about the twelfth time I've said it.  From now
on, anyone who thinks otherwise goes on the clock and gets
a bill from me for my services.  I don't have time to play
games with little babies who whine "why?" every time I say
something, UNLESS they're paying me by the hour.  Then I have
all damn day.

				--Blair
				  "Either get an education or
				   utilize the one you told your
				   employer you'd earned."

diamond@tkou02.enet.dec.com (diamond@tkovoa) (05/29/90)

In article <1990May25.092150.24611@gdr.bath.ac.uk> exspes@gdr.bath.ac.uk (P E Smee) writes:

>One benefit of 'for(;;)' over 'while (1)' which I haven't seen
>mentioned is that most (in my experience) versions of 'lint' will
>cheerfully accept 'for(;;)' without comment, while giving a 'constant
>in conditional' warning for 'while(1)'.

#ifdef LINT
    for(;;) {
#else
    while(1) {
#endif
    :-)

(Of course lint is broken.  Broken tools were desirable in those days.)

(Follow-ups to comp.lang.c, because this topic does not belong in comp.std.c)
-- 
Norman Diamond, Nihon DEC     diamond@tkou02.enet.dec.com
Proposed group comp.networks.load-reduction:  send your "yes" vote to /dev/null.

aipdc@castle.ed.ac.uk (Paul D. Crowley) (05/29/90)

bph@buengc.bu.edu (Blair P. Houghton) sez in <5915@buengc.BU.EDU>
>>The standard does *NOT* say, in any way, shape, or form, that they are
>>"exactly the same, when translated into object code without thinking
>>about it".
>
>That's it.
>
>If one more person puts words in my mouth without my
>permission, I'm going to fucking ram my fucking terminal
>up their fucking groin.
>
>	I NEVER SAID IT DID, YOU OBSTREPEROUS FUCKING ASSHOLE!!!
>
>Have you and Doug been sucking pills out of the same prescription
>of Stupidity?  Where the hell do you get the idea that I say that
>ANSI X3.159-1989 says how to generate code?

Blair, you're way out of line posting this on comp.std.c.   Take insults
to alt.flame.

In any case, you definitely seemed to imply that you were talking about
code.  Consider:

* You raised the issue because the standard states that for(;;) means
for (;1;) which you said meant that it could be no more efficient than
while(1).  Since everybody already knew they were identical in meaning,
seems to me all you can be talking about is the efficiency of the code
generated.  In other words, the standard specified that the _code_
_generated_ must have an extra comparison.

* If you're not worried about the code generated so long as it does what
the standard says it should, why the hell were you complaining about
"optimization without your permission"?

* I seem to remember your saying that a compiler which didn't produce
the same code for these two cases would be breaking the law, if it
claimed to adhere to the ANSI standard.

Blair, people are wrong all the time.  No doubt Doug and Gwyn often make
mistakes.  Why can't you say "Oh, yes, mea culpa" and keep quiet instead
of denying you ever said that (praying that no-one can be bothered to
dredge up the relevant articles) and flaming the people kind enough to
point it out?
-- 
\/ o\ Paul Crowley aipdc@uk.ac.ed.castle
/\__/ "Trust me, I know what I'm doing" - Sledge Hammer

gwyn@smoke.BRL.MIL (Doug Gwyn) (05/29/90)

In article <5915@buengc.BU.EDU> bph@buengc.bu.edu (Blair P. Houghton) writes:
-In article <3398@auspex.auspex.com> guy@auspex.auspex.com (Guy Harris) writes:
-Because in article <5879@buengc.BU.EDU> I [bph] said, in my own words, precisely:
->>	for(;;) statement
->>	while(1) statement
->>	label: statement if(1) goto label;
->>are all the same; exactly the same, when translated into object code
->>without thinking about it.  You could contend that the third is
->>my invention, but the standard says the first two are identical.
->The standard does *NOT* say, in any way, shape, or form, that they are
->"exactly the same, when translated into object code without thinking
->about it".
-... Where the hell do you get the idea that I say that
-ANSI X3.159-1989 says how to generate code?

I bet he gets the idea from the same place I do: your own words!

-From: bph@buengc.BU.EDU (Blair P. Houghton)
-Newsgroups: comp.std.c
-Subject: for(;;) vs. while(1) is a draw
-Message-ID: <5876@buengc.BU.EDU>
-Date: 22 May 90 20:52:33 GMT
-The standard states (Sec. 3.6.5.3, pp. 80) that omitting the
-first or third expressions in `for( e1; e2; e3 )' replaces
-them with void expressions, but that if the second is omitted
-it's "replaced by a nonzero constant."
-This means that now, assuming that the compiler chooses 1 as
-the "nonzero constant,"
-	for (;;) statement
-and
-	while (1) statement
-are identical _in_every_way_ and there's no reason for
-a programmer to expect more-optimal behavior from the
-former (it's an old argument that the slight obfuscation
-of the empty-for is balanced by a greater probability that
-the compiler will make faster, smaller object-code from it).

Your use of "The standard states ... This means that now ..."
conveys the implication that you think the subject was affected
by the issuance of the standard.  Indeed, why bring this subject
up at all in this newsgroup if you believed it has no relation
to the standard?

-From: bph@buengc.BU.EDU (Blair P. Houghton)
-Newsgroups: comp.std.c
-Subject: Re: for(;;) vs. while(1) is a draw
-Message-ID: <5879@buengc.BU.EDU>
-Date: 23 May 90 17:06:48 GMT
-(I.e., and we can move this to alt.flame if you like,
-despite the timelessness of your ego you're gonna die long
-before C does, and not everyone needs to cling to "the old
-ways."  The standard also remaindered `=-' forevermore; do
-you want it back to provide compatibility with the "Hello,
-world!!!!" program you wrote back in 1979?)
-In article <12955@smoke.BRL.MIL> gwyn@smoke.BRL.MIL (Doug Gwyn) writes:
->Secondly, I don't know why you think the standard changes anything
->whatsoever in the way that compilers must treat these constructs.
->It doesn't.  They mean EXACTLY what they have always meant, and
->EXACTLY the same code can be generated for them as before the standard.
-"Can" is not "will," and "must" is not "may."
-Before, an implementor that claimed their compiler did _no_
-optimization could still turn `for(;;)' into an
-unconditional branch, whereas `while(1)' was still forced
-to compare-1-to-0-and-branch-if-not-equal.  ...
-The obvious optimization
-(possibly through a `-O' option) is to turn `while(1)' into
-an unconditional branch, just like `for(;;)' was always.
-Now, the standard has made it clear that without any
-optimization BOTH constructs will become compare-and-
-branch, and with or without optimization there has to be
-some point where the compilation acts as if `for(;;)' had
-been written `for(;1;)', which is to say (since the std is
-explicit on this; ANSI X3.159-1989, Sec. 3.6.5.3, pp. 79,
-ll. 31-39), as if it had been written `while(1)'.
-"The semantic descriptions in this standard describe the behavior
-of an abstract machine in which issues of optimization are irrelevant."
-(ANSI X3.159-1989, Sec. 2.1.2.3, pp. 8, ll. 29-30)
-An implementor that claimed to have a non-optimizing mode
-on an ANSI-conforming compiler which then generated
-different object code for the two constructs would be
-committing fraud.  You can prove that and make it stick.

In this one you were apparently claiming that there are
different "old" and "new" ways, and you were continuing
your argument that the standard will have some effect on
this subject.  You stated explicitly that "the standard
has made it clear that without any optimization ...",
which is of course wrong as the standard never mentions
presence or absence of optimization, and in fact applies
uniformly to all conforming implementations no matter
what degree or kind of optimizations they apply.

-Path: smoke!adm!husc6!encore!bu.edu!buengc!bph
-From: bph@buengc.BU.EDU (Blair P. Houghton)
-Newsgroups: comp.std.c
-Subject: Re: for(;;) vs. while(1) is a draw
-Message-ID: <5897@buengc.BU.EDU>
-Date: 24 May 90 16:09:49 GMT
-In article <12971@smoke.BRL.MIL> gwyn@smoke.BRL.MIL (Doug Gwyn) writes:
->This has nothing to do with for(;;) and while(1), which, AS I
->SAID, have not changed one iota as the result of the standard.
-Wrong.  Never before has anything at all been said about
-adding '1' to the conditional expression in a
-for-statement.  You're implying that X3J11 could well have
-left that sentence entirely out of the standard.  For all
-the difference it makes to *optimized* programs, it could
-have; but a null expression is not a logical truism, so
-they made it clear that a missing conditional is replaced
-by 1 in this context.

Here you flatly contradicted my assertion that the standard
has changed nothing about the subject, and again you tried to
express this in terms of optimization (i.e. code generation).

jsdy@hadron.COM (Joseph S. D. Yao) (05/29/90)

In article <5916@buengc.BU.EDU> bph@buengc.bu.edu (Blair P. Houghton) writes:
>In article <0:P3-A6@ggpc2.ferranti.com> peter@ficc.ferranti.com (Peter da Silva) writes:
>>In article <5904@buengc.BU.EDU> bph@buengc.bu.edu (Blair P. Houghton) writes:
>>> When did I say otherwise?
...
>I did not say the standard requires a compiler to generate
>code in any particular way.  I said that a compiler that
>the implementor claimed to be matching the standard's model
>of a hypothetical machine would, in fact, generate
>identical code for !while(1)!  and !for(;;)!.

Well, I was going to mention that this newsgroup was supposed to be
talking about the C standard, not on "implementation details."  I was
also tempted to say something biting about people who were compelled to
use profligate and utterly gratuitous profanity to try to make some
kind of point, and then called others babies.  However, we now have The
Man's Own Words, so let's see if I wasted thousands of dollars on a
degree in Logic.

While English is an inherently ambiguous language (as are all natural
languages, this being part of their compelling power), I think most
would agree that "... a compiler that the implementor claimed ...
[above]" Is logically equivalent to "If the implementor claims that a
compiler matches the standard's model of a hypothetical machine, then
that compiler would, in fact [or, necessarily - j] generate identical
code for ...".  Now, our universe of discourse in this newsgroup is
precisely the C standard and matters pertaining to it.  Compilers for
which the "If" clause of the above statement are untrue are, for our
purposes, not within the universe of discourse.  Therefore, let us
assume the "If" clause trivially true.  The statement then boils down
to "That compiler would [necessarily] generate identical code for ...".
Now, The Man has stated that he is not saying "the standard requires a
compiler to generate code in any particular way."  My perception is
that there is a contradiction here.

Now, I admit to being human, and making a lot of errors, even some
obvious ones.  My wife would certainly agree to that (sometimes).  So
perhaps my perception here is flawed.  I'm sure I made a mistake in the
introduction, namely, if I want a certain person to read this object-
ively, I shouldn't have referred slightingly to language habits over
which he perhaps has no control.  However, if I have made any mistakes
in the above analysis, I would appreciate people MAILing them to me,
and I will post any reasonable ones I receive.  Thank you.

	Joe Yao				jsdy@hadron.COM
	( jsdy%hadron.COM@{uunet.UU.NET,decuac.DEC.COM} )
	arc,arinc,att,avatar,blkcat,cos,decuac,\
	dtix,ecogong,grebyn,inco,insight,kcwc,  \
	lepton,lsw,netex,netxcom,phw5,research,  >!hadron!jsdy
	rlgvax,seismo,sms,smsdpg,sundc,telenet, /
	uunet				       /
(Last I counted ...)

diamond@tkou02.enet.dec.com (diamond@tkovoa) (05/30/90)

Followups to comp.lang.c, where most of this belongs.

In article <3093@goanna.cs.rmit.oz.au> ok@goanna.cs.rmit.oz.au (Richard A. O'Keefe) writes:

>I loathe and detest while (1) because it's obfuscatory.
>The thing is, a skilled programmer uses a while (..) statement because
>that's the way it fell out of his preconditions, postconditions,
>invariant, and so on.  You use 'while' to express "here after this
>keyword is all the information you need about when the loop stops."

Exactly the same reasoning applies to the second expression in a
"for" statement.  You use "for" to express "the second expression
after this keyword is all the information you need about when the
loop stops."
(My opinion and argument here are serious, not intended to be satirical.)

>The character sequence (;;) has, I believe, no other use in C.  It's a
>very clear signal "no, it _wasn't_ a mistake, I really _did_ mean to
>put the real loop control somewhere else."

while(1) is an equally clear signal.

>In fact, I would welcome a "lint" option that reported 'break' or
>'continue' statements having a while (..) or do while (..) statement
>as scope as being likely errors.

I loathe and detest all "break" and "continue" statements.  The
language should have been designed differently.  Nonetheless,
"break" and "continue" are suitable for while(1) and for(;;) loops.
Reading becomes difficult when "break" or "continue" occurs in either
a "while" or "for" loop with non-constant terminating condition.

>Um, I've recently had a lot more contact with people from a Pascal
>background than I really wanted.  Quickly now, what's wrong with this:
>	program main;
>	    var i: integer;
>	    procedure p(n: integer);
>		begin
>		    for i := 1 to n do write(' ');
>		    writeln(i);
>		end;
>	    begin
>		p(10);
>	    end.
>(I count three violations of the Pascal Standard.)

Then read the Pascal Standard and count again.  There is one violation.
(Did you think that Pascal lacks a null statement?)

-- 
Norman Diamond, Nihon DEC     diamond@tkou02.enet.dec.com
Proposed group comp.networks.load-reduction:  send your "yes" vote to /dev/null.

tneff@bfmny0.BFM.COM (Tom Neff) (05/30/90)

Kee-rist but this is unedifying!  Surely it could be better settled
with water balloons. :-)

bph@buengc.BU.EDU (Blair P. Houghton) (05/30/90)

In article <894@hadron.COM> jsdy@hadron.UUCP (Joseph S. D. Yao) writes:
>In article <5916@buengc.BU.EDU> bph@buengc.bu.edu (Blair P. Houghton) writes:
>>I did not say the standard requires a compiler to generate
>>code in any particular way.  I said that a compiler that
>>the implementor claimed to be matching the standard's model
>>of a hypothetical machine would, in fact, generate
>>identical code for !while(1)!  and !for(;;)!.
>
>we now have The
>Man's Own Words, so let's see if I wasted thousands of dollars on a
>degree in Logic.

Do, let's.

>While English is an inherently ambiguous language (as are all natural
>languages, this being part of their compelling power), I think most

Flummery at the outset.  "The logic of language is in its syntax,"
Rudy Carnap, _The Logical Syntax of Language_, 1937 (or was it 1939?).
I'll agree that, when misused or misread, or explicitly seeded with
ambiguity, any language can express ambiguity.  However, no language
is intrinsically ambiguous.  Their "compelling power" is moot.

>would agree that "... a compiler that the implementor claimed ...
>[above]" Is logically equivalent to "If the implementor claims that a
>compiler matches the standard's model of a hypothetical machine, then
>that compiler would, in fact [or, necessarily - j] generate identical
>code for ...".

Better, but this is just the summary of what's gone before.

>Now, our universe of discourse in this newsgroup is
>precisely the C standard and matters pertaining to it.
>Compilers for which the "If" clause of the above statement
>are untrue are, for our purposes, not within the universe
>of discourse.

Fail.  There is no "universe of discourse."  Any group may have
a certain central theme, but it is likely through pure entropy
to contain topics completely unrelated, and justifiably
often may contain topics just beyond the fringes of the theme.

>Therefore, let us
>assume the "If" clause trivially true.

You made the right choice, but for the wrong reasons.
You should first assume it true and examine the effect on
what follows; then you should assume it false and examine
the effect.  If you did, you'd find it quite consistent.

>The statement then boils down
>to "That compiler would [necessarily] generate identical code for ...".
>Now, The Man has stated that he is not saying "the standard requires a
>compiler to generate code in any particular way."  My perception is
>that there is a contradiction here.

Your perception is utterly bogus, especially since your logic
(up to the words "there is a contradiction") seems correct,
even if your assumptions are untenable.

"The Man" does not claim that the standard requires an
conforming compiler to generate code in any particular way
(nor even to generate code, which makes it not much of a
compiler, eh?).  It is the _implementor's_ decision to
follow the standard's syntax and semantics precisely, to the
letter, and without optimization; and, it is the
_implementor's_ claim that it does so that produces that
requirement.

You may argue that such claims still produce no
requirement, and you'd get an argument back.  That's fine.
You might even convince me that I'm wrong on that point.
Don't bet real money on it, though.  What I refuse to be
civil about, however, is the cavalier disregard some people
seem to have for logically complete statements.

Doug's now posted several of my prior messages and made
illogical inferences from them, following exactly this
fallacy:  he and everyone else seems to ignore the
subjunctive clause "if the implementor claims..."

This is reprehensible among logicians (what do you think
is the principal function of standards and regulations),
and deserves neither mercy nor civility.

>Now, I admit to being human, and making a lot of errors, even some
>obvious ones.  My wife would certainly agree to that (sometimes).  So
>perhaps my perception here is flawed.  I'm sure I made a mistake in the
>introduction, namely, if I want a certain person to read this object-
>ively, I shouldn't have referred slightingly to language habits over
>which he perhaps has no control.  However, if I have made any mistakes
>in the above analysis, I would appreciate people MAILing them to me,
>and I will post any reasonable ones I receive.  Thank you.

Again, a fallacy.  If you post, you are open to replies in
public, especially when your contentions are in the vein of
denigrating the writings of others, however even-handed and
calm you may be.

				--Blair
				  "Courtesy is fine, but don't expect
				   social courtesy when you're breaking
				   the rules of logic left and right."

peter@ficc.ferranti.com (Peter da Silva) (05/30/90)

In article <5916@buengc.BU.EDU> bph@buengc.bu.edu (Blair P. Houghton) writes:
> In article <0:P3-A6@ggpc2.ferranti.com> peter@ficc.ferranti.com (Peter da Silva) writes:
> >you said the standard requires the compiler generate identical code
> >for !while(1)! and !for(;;)!.

> I said that a compiler that
> the implementor claimed to be matching the standard's model
> of a hypothetical machine would, in fact, generate
> identical code for !while(1)!  and !for(;;)!.

I'm sorry, but I can't see any significant difference between these two
statements.

Perhaps you should try turning on your English language optimiser?
-- 
`-_-' Peter da Silva. +1 713 274 5180.  <peter@ficc.ferranti.com>
 'U`  Have you hugged your wolf today?  <peter@sugar.hackercorp.com>
@FIN  Dirty words: Zhghnyyl erphefvir vayvar shapgvbaf.

bph@buengc.BU.EDU (Blair P. Houghton) (05/30/90)

In article <4298@castle.ed.ac.uk> aipdc@castle.ed.ac.uk (Paul D. Crowley) writes:
>bph@buengc.bu.edu (Blair P. Houghton) sez in <5915@buengc.BU.EDU>
>>	V ARIRE FNVQ VG QVQ, LBH BOFGERCREBHF SHPXVAT NFFUBYR!!!

>Blair, you're way out of line posting this on comp.std.c.   Take insults
>to alt.flame.

I thought I had; or at least crossposted.

I do apologize to most of you, at least the ones who haven't
continually misinterpreted what I've been saying.

>In any case, you definitely seemed to imply that you were talking about
>code.  Consider:

It seems to have been taken that way, and I was talking about
code as an end-product, but I didn't anywhere leave lying
around the idea that the standard refused to allow
optimizations, disoptimizations, or even the generation of
player-piano rolls (as long as they handle their input and
produce their output correctly) from conforming programs.
In fact, I stated several times that it didn't.  I quoted
the section mooting optimization.  I made it so clear that
I understood and wanted to make it understood that a compiler
was free to optimize that when people kept ignoring those
clarifications I could only assume that they were either
mentally deficient, incomprehending, or just being malicious.

>* You raised the issue because the standard states that for(;;) means
>for (;1;) which you said meant that it could be no more efficient than
>while(1).  Since everybody already knew they were identical in meaning,
>seems to me all you can be talking about is the efficiency of the code
>generated.  In other words, the standard specified that the _code_
>_generated_ must have an extra comparison.

Now _you're_ missing the condition that the implementor's
implied that it's not optimizing.  If it has, then your
last statement should be true.  If it hasn't, that statement
may or may not be true.

>* If you're not worried about the code generated so long as it does what
>the standard says it should, why the hell were you complaining about
>"optimization without your permission"?

Because I don't like compilers that get ahead of my debugging.
When the time comes to make the object code tiny and quick, it
will have at least been confirmed logically (to some level
of satisfaction).

>* I seem to remember your saying that a compiler which didn't produce
>the same code for these two cases would be breaking the law, if it
>claimed to adhere to the ANSI standard.

It also had to claim to eschew all forms of optimization.

>Blair, people are wrong all the time.  No doubt Doug and Gwyn often make
>mistakes.  Why can't you say "Oh, yes, mea culpa" and keep quiet instead

I did say exactly that when someone (you?  Karl Heuer?  Someone else?)
pointed out that K&R1 actually did explicitly state that the second
expression in an empty-for was to be replaced by a `1'.  I've NEVER
tried to hide my mistakes.  Go ahead and prove me wrong.  I'll applaud
you for it.

>of denying you ever said that (praying that no-one can be bothered to
>dredge up the relevant articles) and flaming the people kind enough to
>point it out?

Because this is not a mistake.  I was very careful to say what I
meant to say and they repeatedly ignored the first half of my
arguments.  You may think that anger and profanity have no place
in reasoned debate, and I agree, but when people drop half of the
reason the rules (explicit or otherwise) of the debate become moot.

				--Blair
				  "To live a sheltered
				   life is to waste it."

bph@buengc.BU.EDU (Blair P. Houghton) (05/30/90)

In article <13009@smoke.BRL.MIL> gwyn@smoke.BRL.MIL (Doug Gwyn) writes:
>In article <5915@buengc.BU.EDU> bph@buengc.bu.edu (Blair P. Houghton) writes:
>-... Where the hell do you get the idea that I say that
>-ANSI X3.159-1989 says how to generate code?
>
>I bet he gets the idea from the same place I do: your own words!

Not the way they're written, he doesn't.

>-In article <3398@auspex.auspex.com> guy@auspex.auspex.com (Guy Harris) writes:
>-Because in article <5879@buengc.BU.EDU> I [bph] said, in my own words, precisely:

>Your use of "The standard states ... This means that now ..."
>conveys the implication that you think the subject was affected
>by the issuance of the standard.  Indeed, why bring this subject
>up at all in this newsgroup if you believed it has no relation
>to the standard?

I've already admitted I was wrong to think that K&R didn't
explicitly state what the standard states.  I admitted it
a week ago.  You forgot to include _that_ article, or maybe
you didn't forget.  In any case, that's not at issue, any
more.  What is at issue is the position that I said that
the standard requires code to be generated in any particular
way.  I never said it.  Don't say I did.  You can't show
I did.  I didn't.  Nope.  Never.

>-From: bph@buengc.BU.EDU (Blair P. Houghton)
>-Newsgroups: comp.std.c
>-Subject: Re: for(;;) vs. while(1) is a draw
>-Message-ID: <5879@buengc.BU.EDU>
>-Date: 23 May 90 17:06:48 GMT
>-(I.e., and we can move this to alt.flame if you like,
>-despite the timelessness of your ego you're gonna die long
>-before C does, and not everyone needs to cling to "the old
>-ways."  The standard also remaindered `=-' forevermore; do
>-you want it back to provide compatibility with the "Hello,
>-world!!!!" program you wrote back in 1979?)
>-In article <12955@smoke.BRL.MIL> gwyn@smoke.BRL.MIL (Doug Gwyn) writes:
>->Secondly, I don't know why you think the standard changes anything
>->whatsoever in the way that compilers must treat these constructs.
>->It doesn't.  They mean EXACTLY what they have always meant, and
>->EXACTLY the same code can be generated for them as before the standard.
>-"Can" is not "will," and "must" is not "may."
>-Before, an implementor that claimed their compiler did _no_
>-optimization could still turn `for(;;)' into an
>-unconditional branch, whereas `while(1)' was still forced
>-to compare-1-to-0-and-branch-if-not-equal.  ...
>-The obvious optimization
>-(possibly through a `-O' option) is to turn `while(1)' into
>-an unconditional branch, just like `for(;;)' was always.
>-Now, the standard has made it clear that without any
>-optimization BOTH constructs will become compare-and-
>-branch, and with or without optimization there has to be
>-some point where the compilation acts as if `for(;;)' had
>-been written `for(;1;)', which is to say (since the std is
>-explicit on this; ANSI X3.159-1989, Sec. 3.6.5.3, pp. 79,
>-ll. 31-39), as if it had been written `while(1)'.
*******************************************************************
>-"The semantic descriptions in this standard describe the behavior
>-of an abstract machine in which issues of optimization are irrelevant."
>-(ANSI X3.159-1989, Sec. 2.1.2.3, pp. 8, ll. 29-30)
*******************************************************************
>-An implementor that claimed to have a non-optimizing mode
>-on an ANSI-conforming compiler which then generated
>-different object code for the two constructs would be
>-committing fraud.  You can prove that and make it stick.
>
>In this one you were apparently claiming that there are
>different "old" and "new" ways,

Again, that's been settled.  The standard didn't say
anything that K&R didn't say.  That doesn't change my
contention that there are compilers that will have to be
fixed if they want to claim X3.159 conformance _and_ a lack
of optimization.  (We can still argue this if you like, but
it fits better in comp.misc under the subject-line "What is
optimization?")

>and you were continuing
>your argument that the standard will have some effect on
>this subject.  You stated explicitly that "the standard
>has made it clear that without any optimization ...",

That's the closest you've come to putting a foundation
under this entire misinterpretation, and I can see where
you might.  You're applying "made it clear" to "without any
optimization" and inferring that I'm saying "states how not
to optimize".  It's a wrong reading, in itself, and
tragically flawed in the face of the next development:

>which is of course wrong as the standard never mentions
>presence or absence of optimization, and in fact applies
>uniformly to all conforming implementations no matter
>what degree or kind of optimizations they apply.

Which is almost exactly what I and the standard say in the
three lines demarcated above by the asterisks, except for the
"never mentions" crack.  You think I dig out all those
reference numbers just because it's fun?  (It _is_ fun, but
it's not _just_ fun.) You think I'm capable of contradicting
myself within the space of a kilobyte and not seeing it?

Your opinion of me must be even lower than mine of you,
but at least I've got some basis for mine.

>-Path: smoke!adm!husc6!encore!bu.edu!buengc!bph
>-From: bph@buengc.BU.EDU (Blair P. Houghton)
>-Newsgroups: comp.std.c
>-Subject: Re: for(;;) vs. while(1) is a draw
>-Message-ID: <5897@buengc.BU.EDU>
>-Date: 24 May 90 16:09:49 GMT
>-In article <12971@smoke.BRL.MIL> gwyn@smoke.BRL.MIL (Doug Gwyn) writes:
>->This has nothing to do with for(;;) and while(1), which, AS I
>->SAID, have not changed one iota as the result of the standard.
>-Wrong.  Never before has anything at all been said about
>-adding '1' to the conditional expression in a
>-for-statement.  You're implying that X3J11 could well have
>-left that sentence entirely out of the standard.  For all
>-the difference it makes to *optimized* programs, it could
>-have; but a null expression is not a logical truism, so
>-they made it clear that a missing conditional is replaced
>-by 1 in this context.
>
>Here you flatly contradicted my assertion that the standard
>has changed nothing about the subject, and again you tried to
>express this in terms of optimization (i.e. code generation).

Two different things, and you've won the first.  There's a
bare lack of anything in the rationale on the replacement
of that '1'.  I noticed this, and it could have clued me
to the fact that there must have been prior art, if I'd
realized that prior art doesn't need rationale.

"For all the difference it makes to *optimized* programs"
is yet another direct statement making it clear that I
never thought the standard specified code generation.
I wasn't too ambiguous anywhere else, either.

				--Blair
				  "Except maybe down here."

gwyn@smoke.BRL.MIL (Doug Gwyn) (05/31/90)

In article <5926@buengc.BU.EDU> bph@buengc.bu.edu (Blair P. Houghton) writes:
>Doug's now posted several of my prior messages and made
>illogical inferences from them, following exactly this
>fallacy:  he and everyone else seems to ignore the
>subjunctive clause "if the implementor claims..."

No, I haven't ignored that because you didn't use that qualifier
in (most of) the cases I quoted.

However, if we are to believe your current assertion that you
were only discussing what would be true when some implementor
claims to be literally implementing the abstract C machine,
then we should ask what is the point of your wasting our time
posting about such an empty subject.  There is no implementor
dumb enough to attempt to make such a claim, because there is
no actual computer architecture for which such a project could
be accomplished.  For real architectures, some degree of
non-trivial (i.e. not one-to-one) translation between the
abstract machine operations and executable code is a necessity.

ok@goanna.cs.rmit.oz.au (Richard A. O'Keefe) (05/31/90)

In article <5927@buengc.BU.EDU>, bph@buengc.BU.EDU (Blair P. Houghton) writes:
[ you know what he has been writing ]

I want to apologise to Blair Houghton.
I have been reading all his postings on this topic, and the only
interpretation which suggested itself to me was that he was saying
that a compiler could not truthfully be said to conform to the standard
unless under certain conditions about claims about optimisation which
aren't quite clear to me, it generates _exactly_ the same code for
while(1) and for(;;).

So I understood his postings in the same sense as Doug Gwyn and the rest.
Obviously, I'm misreading him.  I _think_ my difficulty lies in seeing
what counts as optimisation.  For example, if we consider a compiler
which generates assembly code, should the labels generated have exactly
the same spelling?  If the for(;;) code has an extra unused label (it's
easy to imagine a dumb compiler planting a jump around nothing to
handle expr-3 and then the peep-hole optimiser deleting the jump and
leaving the label), does that count as identical code or not?  Please,
this is serious.  I want to know what it is about object code
generated under this or that claim about optimisation which the ANSI
C standard can govern.  I haven't a current copy of the standard, so
it may well say all sorts of things, for all _I_ know to the contrary.

In particular, given the possibility of "compiling" C by stuffing it
through lexical passes alone and executing the token sequence
interpretively, how can _any_ compiler writer truthfully claim to be
doing "no optimisation" in the sense required?  I don't understand this.
Who are the compiler writers who are making this claim?

> Because I don't like compilers that get ahead of my debugging.
Can't disagree with that; on the other hand, when I skip over a
procedure call, I'd rather not wait for it too long.  Just as long
as the compilers don't get too far ahead of _their_ debugging (:-).

-- 
"A 7th class of programs, correct in every way, is believed to exist by a
few computer scientists.  However, no example could be found to include here."

bph@buengc.BU.EDU (Blair P. Houghton) (05/31/90)

In article <:0T3AHF@xds13.ferranti.com> peter@ficc.ferranti.com (Peter da Silva) writes:
>In article <5916@buengc.BU.EDU> bph@buengc.bu.edu (Blair P. Houghton) writes:
>> In article <0:P3-A6@ggpc2.ferranti.com> peter@ficc.ferranti.com (Peter da Silva) writes:
>> >you said the standard requires the compiler generate identical code
>> >for !while(1)! and !for(;;)!.
>
>> I said that a compiler that
>> the implementor claimed to be matching the standard's model
>> of a hypothetical machine would, in fact, generate
>> identical code for !while(1)!  and !for(;;)!.
>
>I'm sorry, but I can't see any significant difference between these two
>statements.

Oh, good.  A paying customer.  This is exactly the sort
of non-comprehension that makes lawyers blithely rich while
being their usual, stupid selves.

Okay; comprehension by parts:

The first statement, "the standard requires the compiler,"
would mean that the compiler would have no choice.  This
is patently false, but can be true for much of the standard
when you assume the existence of an implied condition that
can be stated "if the compiler claims X3.159 conformance";
even so, it does not apply to the portion of the standard
under contention.

The second statement, "a compiler that the implementor
claimed," involves claims by one side in an implied
contract.  These claims then must be supported by the
performance of the product; otherwise, a litigable and/or
criminal situation will ensue.

The difference is that the first statement is false, and the
second statement indicates that the implementor has constrained
his own product, and thus can not be false unless elsewhere
contravened by the implementor's own claims (i.e., don't forget
to read the fine print on the fine print).

>Perhaps you should try turning on your English language optimiser?

What, and deprive you of a heapin' helpin' of my wonderful legalese?

				--Blair
				  "Will that be cash, certified check,
				   or do you just want to run up a tab?"

harrison@necssd.NEC.COM (Mark Harrison) (05/31/90)

In article <4193@castle.ed.ac.uk>, aipdc@castle.ed.ac.uk (Paul D. Crowley) writes:
> Besides which, what are the first three letters of forever?

Then how about:
#define EVER (;;)
for EVER
(Many :-)
-- 
Mark Harrison             harrison@necssd.NEC.COM
(214)518-5050             {necntc, cs.utexas.edu}!necssd!harrison
standard disclaimers apply...

harrison@necssd.NEC.COM (Mark Harrison) (05/31/90)

In article <5879@buengc.BU.EDU> bph@buengc.bu.edu (Blair P. Houghton) writes:
>It's more logical.

Be careful.  Too many times "more logical" == "what I am used to".

Besides, both "for (;;)" and "while (1)" are easy once someone
can accept the obviously impossible proposition "x = x + 1".
-- 
Mark Harrison             harrison@necssd.NEC.COM
(214)518-5050             {necntc, cs.utexas.edu}!necssd!harrison
standard disclaimers apply...

darcy@druid.uucp (D'Arcy J.M. Cain) (06/01/90)

In article <:0T3AHF@xds13.ferranti.com>
peter@ficc.ferranti.com (Peter da Silva) writes:
>In article <5916@buengc.BU.EDU> bph@buengc.bu.edu (Blair P. Houghton) writes:
>> In article <0:P3-A6@ggpc2.ferranti.com> peter@ficc.ferranti.com (Peter da Silva) writes:
>> >you said [...]
>> I said [...]

did not.
did too.
etc.

Uh, if all the discussion is about who actually said what perhaps you could
take it to e-mail and report back who was right when you have it settled.  We
will all wait with baited breath for the outcome of that one.  (Yeh, sure.)

-- 
D'Arcy J.M. Cain (darcy@druid)     |   Government:
D'Arcy Cain Consulting             |   Organized crime with an attitude
West Hill, Ontario, Canada         |
(416) 281-6094                     |

peter@ficc.ferranti.com (Peter da Silva) (06/01/90)

In article <5931@buengc.BU.EDU> bph@buengc.bu.edu (Blair P. Houghton) indulges
in a bunch of legalistic hairsplitting.

So the question comes down to whether the phrase "the compiler claims
X3.159 conformance" is equivalent to "the implementor claimed to be
matching the standard's model of a hypothetical machine". Since the
standard (X3.159) is defined in terms of this hypothetical machine, this
is such a fine point that only a lawyer would care about the difference...

> Oh, good.  A paying customer.  This is exactly the sort
> of non-comprehension that makes lawyers blithely rich while
> being their usual, stupid selves.

Are you a lawyer?
-- 
`-_-' Peter da Silva. +1 713 274 5180.  <peter@ficc.ferranti.com>
 'U`  Have you hugged your wolf today?  <peter@sugar.hackercorp.com>
@FIN  Dirty words: Zhghnyyl erphefvir vayvar shapgvbaf.

tj@mks.com (Trevor John Thompson) (06/01/90)

In article <5927@buengc.BU.EDU> bph@buengc.bu.edu (Blair P. Houghton) writes:
>In article <4298@castle.ed.ac.uk> aipdc@castle.ed.ac.uk (Paul D. Crowley) writes:
>>* You raised the issue because the standard states that for(;;) means
>>for (;1;) which you said meant that it could be no more efficient than
>>while(1).  Since everybody already knew they were identical in meaning,
>>seems to me all you can be talking about is the efficiency of the code
>>generated.  In other words, the standard specified that the _code_
>>_generated_ must have an extra comparison.
>
>Now _you're_ missing the condition that the implementor's
>implied that it's not optimizing.  If it has, then your
>last statement should be true.  If it hasn't, that statement
>may or may not be true.
>
>>* If you're not worried about the code generated so long as it does what
>>the standard says it should, why the hell were you complaining about
>>"optimization without your permission"?
>
>Because I don't like compilers that get ahead of my debugging.
>When the time comes to make the object code tiny and quick, it
>will have at least been confirmed logically (to some level
>of satisfaction).
>
>>* I seem to remember your saying that a compiler which didn't produce
>>the same code for these two cases would be breaking the law, if it
>>claimed to adhere to the ANSI standard.
>
>It also had to claim to eschew all forms of optimization.

It would appear that Mr. Houghton has some unusual notions of what
constitutes optimization; which i would guess are not based on
any practical experience with compiler writing. I suggest that
most readers of this group understand optimization to refer to
the kind of program transformation that is based on heuristics,
or falsifiable assumptions, or time and space expensive analysis,
and that the user can request either be applied or eschewed.

Generating an unconditional loop, rather than a test of a constant
followed by a conditional branch, for while(1), is generally
considered good code generation strategy, not an "optimization".
It requires no expensive program analysis to discover that the
unconditional loop is a superior code burst in time and space.
The existence of (old) compilers that do not implement this
strategy does not in any way diminish its validity.

One wonders just how bad code generation must be to satisfy
Mr. Houghton's notions of "non-optimized".
If his debugging techniques rely on the compiler *not* making
such transformations, then he needs a better debugger, or
a better compiler, or better programs.
-- 
     ||  // // ,'/~~\'   Trevor John Thompson  //C++ a strongly hyped language
    /||/// //|' `\\\     Mortice Kern Systems Inc.
   / | //_// ||\___/     35 King St. N., Waterloo, Ont., Can. N2J 2W9
O_/                      tj@mks.com  Vox: 519-884-2251  Fax: 519-884-8861

jwe@ut-emx.UUCP (jwe) (06/01/90)

In article <358@necssd.NEC.COM> harrison@necssd.NEC.COM (Mark Harrison) writes:

> Then how about:
> #define EVER (;;)
> for EVER
> (Many :-)

Or, how about:

#define TRUE 29  /* because it's my favorite lucky (nonzero) number */
while (TRUE)

Does this mean we can turn our flames back toward the real issues of
standard C, such as whether or not it's a good idea to define macros
for TRUE and FALSE?

--
John "I'll bet I'm not the only one that posts useless stuff here" Eaton
jwe@emx.utexas.edu
Department of Chemical Engineering
The University of Texas at Austin
Austin, Texas  78712
-- 
John Eaton
jwe@emx.utexas.edu
Department of Chemical Engineering
The University of Texas at Austin
Austin, Texas  78712

karl@haddock.ima.isc.com (Karl Heuer) (06/01/90)

In article <13025@smoke.BRL.MIL> gwyn@smoke.BRL.MIL (Doug Gwyn) writes:
>... empty subject.  There is no implementor dumb enough to attempt to make
>such a claim ...

This is why I said Blair's statements were vacuously true.


Here's the recap, for those who tuned in late:

* A lot of people don't really care whether you use for(;;) or while(1), and
  wish that such discussion, if it is to take place at all, should be in
  alt.religion.computers.

* Blair happens to prefer while(1) for some reason.  Most of us don't care
  why.

* Evidently someone once told Blair of a compiler that produced slightly
  better code for the `for' statement.  I believe I've seen such a compiler.

* The better-code argument is pretty weak, since any compiler that overlooks
  such an obvious optimization is doing such a poor job that you'd better not
  be using it for anything where you care about compiler efficiency.  At best,
  you can use this argument as a tie-breaker.  (E.g. this is why I originally
  settled on using `++i' rather than `i++'.)

* Blair noted that the ANS, in describing the `for' statement, uses wording
  that (correctly) describes `for(;;)' as equivalent to `while(1)'.  He
  mistakenly thought that this wording was more than just a convenient way to
  describe the semantics, and used this to rebut the better-code argument.

* It turns out the K&R 1 actually does contain a similar clause, not that it
  matters.

* No sane vendor, in the process of upgrading a Classic C compiler to ANSI C,
  is going to change the way code is generated for `for' or `while' on the
  basis of this wording.  Thus, it remains true that `for(;;)' is slightly
  less likely to generate a useless compare.

* A lot of people don't really care whether you use for(;;) or while(1), and
  wish that such discussion, if it is to take place at all, should be in
  alt.religion.computers.

Karl W. Z. Heuer (karl@ima.ima.isc.com or harvard!ima!karl), The Walking Lint
(Isn't this subject in your KILL file yet?)