slang-users mailing list

[2001 Date Index] [2001 Thread Index] [Other years]
[Thread Prev] [Thread Next]      [Date Prev] [Date Next]

RE: while()


Hi All,

RE: McConnell, "Code Complete", M$ Press, pg 333

C Example of Empty Loop:
while ( (InputChar = getch()) != '\n')
;

change to:

do
	InputChar = getch();
while (InputChar != '\n');

jmr opine:
While it works (or should I haven't looked up what gcc/Linux should do here), its kinda bad style.  I can see that because my question is what does gdb say the result of (handle = getnextresult()) is when you step thru it?  And its pretty ugly I think to step thru.  But I may be wrong.

Does the behaviour go away if you to a more verbose style?

What compiler and optimizations(if any) are you using?


Quang Nguyen (Ngo) writes:
 > I'm not sure which compiler you're using, but assignment expressions do
 > return a value.  So, the following is okay:
 > 
 > while ((handle = getnextresult()) != NULL)
 >   {
 >   ...
 >   }
 > 
 > --
 > Quang Nguye^~n (Ngo^)
 > 
 > 
 > > -----Original Message-----
 > > From: John E. Davis [mailto:davis@xxxxxxxxxxxxx]
 > > Sent: Wednesday, April 25, 2001 7:27 PM
 > > To: rvanzon@xxxxxxxxxxxx; slang-workers@xxxxxxxxxxxxxxxxxxxxxxxxxx
 > > Subject: Re: while()
 > >
 > >
 > > Richard van Zon <rvanzon@xxxxxxxxxxxx> wrote:
 > > >Hi,
 > > >
 > > >Am I right that this little piece of code doesn't work ?
 > > >I get an stack underflow with it :
 > > >
 > > >while((handle=getnextresult())!=NULL)
 > > >{
 > > >  ...
 > > >}
 > >
 > > Assigment expressions do not return a value.  Hence, you are comparing
 > > NOTHING to NULL.  You can use the comma operator:
 > >
 > >    while (handle = getnextresult (), handle != NULL)
 > >      {
 > >         .
 > > 	.
 > >      }
 > >
 > > --John

-- 
Joe Robertson   -----------------------------
[E]	jmrobert@xxxxxxxx
[W]	http://www.huntsvilleal.com/~jmrobert
[ICQ]	2586528
---------------------------------------------
"I am... after all... a SuperHero."
 Larry-Boy
 http://www.larry-boy.com
---------------------------------------------


[2001 date index] [2001 thread index]
[Thread Prev] [Thread Next]      [Date Prev] [Date Next]