# Excessive optimization (was Re: what was VMS/OpenVMS written in?)

Ian King IanK at vulcan.com
Thu Dec 2 15:19:11 CST 2010

```> -----Original Message-----
> From: cctalk-bounces at classiccmp.org [mailto:cctalk-
> bounces at classiccmp.org] On Behalf Of Philip Pemberton
> Sent: Thursday, December 02, 2010 1:12 PM
> To: General Discussion: On-Topic and Off-Topic Posts
> Subject: Re: Excessive optimization (was Re: what was VMS/OpenVMS
> written in?)
>
> On Thu, 2010-12-02 at 13:32 -0700, Richard wrote:
> > In article <AANLkTi=9NwjfxZvaz2H-btkzt8q-
> c9ErbpNYW+hMfMe=@mail.gmail.com>,
> >     Ethan Dicks <ethan.dicks at gmail.com> writes:
> >
> > > for (;;)
> > >   ;
> >
> > I don't see how this is an infinite loop requiring reset of the
> > processor to escape since the condition clause is empty.  In fact,
> > since the condition clause is empty, I'm not even sure its
> > syntactically valid, but C is strange enough that it may be
> > syntactically valid but not intuititve.
>
> Oh, it's valid. A C for() loop has the following syntax:
>   for (initialiser, condition, loop)
>
> Initialiser is run once before the first loop.
> Condition is validated at the beginning of the loop. If it is TRUE,
> then
> the loop carries on regardless. If the condition is omitted, it is
> assumed to be TRUE.
> Loop is executed once for each time the loop completes, at the end of
> the loop.
>
> So this:
> for (i=0; i<10; i++) {
> 	printf("foo %d\n", i);
> }
>
> Is equivalent to:
> i=0;
> while (i<10) {
> 	printf("foo %d\n", i);
> 	i++;
> }
>
>
> Kernighan & Ritchie "The C Programming Language", Second Edition
> "Revised for ANSI C". Page 60, section 3.5, paragraph 4, last line. I'd
> reference the ANSI standard, but K&R seemed just as good (and more
> accessible) 8^)
>

This discussion puts me in mind of a series of columns in "C Users Journal" about the draft ANSI standard and how it changed behaviors exhibited by some well-known compilers at the time.  The "quiet changes" were the worst: those that caused working programs to fail if recompiled, but generated no warning.  In developing the standard, some things came down to judgement calls, since you could demonstrate successful implementations that were on either side of the question!  -- Ian
```