John Hogerhuis wrote:
The other one I use it for is jumping past the top of
a loop the first
time only (this code probably doesn't work but you get the idea...):
#define DIM(a) (sizeof (a) / sizeof (*(a)))
int ary[4] = {1,3,5,7};
.
.
.
print_ary (ary, DIM (ary));
void print_ary (int *aryp, int n)
{
goto skip_comma;
for (;n;aryp++, n--)
{
printf (", ");
skip_comma:
printf ("%u", *aryp);
}
printf ("\n");
}
I'd do this, and didn't even know that jumping into the middle of the
FOR loop was legal. Even knowing it is legal, I prefer my way (of course):
void print_ary (int *aryp, int n)
{
int i;
for (i=0; i<n; aryp++, i++)
{
if (i>0)
printf (", ");
printf ("%u", *aryp);
}
printf ("\n");
}