Argh
Monday 12th June
What is wrong with the following code? (Bear in mind that ‘create_media’ is a highly complex remote asynchronous task involving ejecting and cueing an audio/video port, creating space, starting video and audio codecs and sending network and serial messages between various devices as each status is reached.)
if (can_create_media(x))
{
bool success;
success = create_media(x);
if (success)
print "media created";
else
print "error: media creation failed";
}
else
{
print "error: can't create media";
}
It looks quite reasonable doesn’t it. That’s until you check the contents of the can_create_media() function. It reads…
bool can_create_media(x)
{
return create_media(x);
}
So that’s why there are multiple replies and race conditions and intermittent failure.
Schoolboy error.
Probably.
rich
12 Jun 06 at 3:34 pm
One for The Daily WTF!
Code Monkey
12 Jun 06 at 4:58 pm
Other functions it would be nice to have implemented with the same coding pattern:
bool can_buy_simon_an_icecream()
{
return buy_simon_an_icecream();
}
Mmm… Undocumented side effects have never tasted so good!
Simon's Tall
12 Jun 06 at 5:09 pm
I’d be renaming that create_media_and_tell_me_if_it_went_swimmingly
Sam
12 Jun 06 at 10:26 pm
Heck, I can’t even get blogger to accept what the internet tells me is a closing tag after it (blogger) decides a tag isn’t closed - despite everything ending with /span between angled brackets as in all the other posts it “transposed” into html for me. But then I have been subject to “intermittent failure” all my life…
qaminante
12 Jun 06 at 10:27 pm
Does this mean you can play Pong now?
Kouros
13 Jun 06 at 7:19 am
haha, I can optimize THAT, sam
sweavo
15 Jun 06 at 3:27 pm