Obscure C code (was Re: Excessive optimization)
Brent Hilpert
hilpert at cs.ubc.ca
Thu Dec 2 21:30:35 CST 2010
On 2010 Dec 2, at 7:16 PM, Brian Lanning wrote:
> When I was working on my CS degree, about a half dozen of us were
> stumped by this one:
>
> int somefunction()
> {
>
> while(somevalue == true);
> {
> printf("test\n");
> }
> }
>
>
> Like the one from brent, it's a little more obvious without all the
> extra code around the problem. The issue is that no matter what we
> put in the criteria, we'd get either exactly one "test", or the while
> loop would get stuck forever printing nothing. I finally did spot it
> after about a hour of staring at it. Maybe we would all have found it
> faster if it hadn't been 3 in the morning with us all pulling
> all-nighters to get the assignment done.
>
Those annoying semi-colons. (Plus I hope you had "true" defined
appropriately.)
More information about the cctalk
mailing list