• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Why cant a function return more than one value?

Page 2 - Seeking answers? Join the AnandTech community: where nearly half-a-million members share solutions and discuss the latest tech.
something as simple as:

while (i != 0)
{
(head, i) = i >> 1;
print("%d", head);
}

To print out a number in binary.

Instead, you have to futz around with bit masks and any number of other hacks to get this to work.
 
Search for elegance in the language you're using, not for language extension. E.g. you could write the above like this (at the same time getting rid of clumsy printf for this single digit output):

do putchar('0'+(i&1)) while (i>>=1);

That's even shorter, and, unlike yours, actually does print "0" for a zero while yours prints nothing at all.

(Both examples print the number LSB first, btw.)
 
Back
Top