'goto" gone from computer languages or is it!
Sean 'Captain Napalm' Conner
spc at conman.org
Mon May 16 16:49:57 CDT 2005
It was thus said that the Great Dave Dunfield once stated:
>
> Given that the original example assumes n > 0 (the test is skipped on
> first entry to the loop), you can accomplish this function with neither
> an extra conditional, superfluous assignment, extra variables or use
> of 'goto'
>
> void print_arg(int *aryp, unsigned n)
> {
> int i;
> for(i=0; ;) {
> printf("%u", aryp[i]);
> if(++i >= n)
> break;
> fputs(", ", stdout); }
> putc('\n', stdout);
> }
Hmmm ...
void print_arg(int *aryp,size_t n)
{
printf("%u",*aryp++);
while(--n)
{
printf(",%u",*aryp++);
}
putchar('\n');
}
-spc (avoids additional variables, no GOTOs, and one conditional ... )
More information about the cctalk
mailing list