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.

Shalmanese

Platinum Member
Sep 29, 2000
2,157
0
0
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.
 

Peter

Elite Member
Oct 15, 1999
9,640
1
0
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.)