Group: comp.lang.c++
From: Jerry Coffin
Date: Sunday, February 17, 2008 4:33 PM
Subject: Re: Breaking from the middle of a loop (C++)

In article <1lwgq0ws7cti7.dlg@gelists.gmail.com>, gelists@gmail.com
says...

[ ... ]

> Not so rare. Most embedded systems have somewhere such a never-ending loop.
> Most services on a normal system have such a loop. Most GUI applications
> have such a loop -- it's a perfectly normal condition for, say, a browser
> or a word processor to be opened and then just stay open until the user
> manually terminates it. The only exception are command line applications.

This is not really true. Just for example, in Windows the standard event
loop looks something like this:

while (GetMessage(&msg, NULL, 0, 0))
{
if (!TranslateMDISysAccel(MdiClient, &msg))
if (!TranslateAccelerator(msg.hwnd, AccelTable, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}

The standard event loop for classic MacOS was in Pascal so I won't quote
it in its entirety here, but it's of the form "repeat ... until gDone;"

For OS/X, the usual event loop is hidden in the core foundation. Looking
at the source for CF-lite, we find CFRunLoopRun, which looks like this:

void CFRunLoopRun(void) {
SInt32 result;
do {
result = CFRunLoopRunSpecific(CFRunLoopGetCurrent(),
kCFRunLoopDefaultMode, 1.0e10, false);
} while (kCFRunLoopRunStopped != result &&
kCFRunLoopRunFinished != result);
}

In short, I'd say the event loops for at least a fair amount of GUI code
does have explicit exit conditions.

I could go on about some of your other claims, but you get the idea --
at best, the statements you've made have more exceptions than you're
claiming. It is true that some code really does use infinite loops from
which exits are never expected -- but such code does not seem to be
nearly as common as you're attempting to imply.

--
Later,
Jerry.

The universe is a figment of its own imagination.

Safety Articles | Usenet Groups | Usenet News | Bluegrass