3 ms·
Actually the one that uses function pointers is by far the best, simplest way, and it doesn't segfault. Since x/1000 will always be floor(x/1000), once it reac
by juiceandjuice 16y ago
Actually the one that uses function pointers is by far the best, simplest way, and it doesn't segfault. Since x/1000 will always be floor(x/1000), once it reaches 1000 it calls nothing and exits cleanly.
This one (not mine):
#include <stdio.h>
void nothing(int);
void next(int);
void (*dispatch[2])(int) = {next, nothing};
void nothing(int x) { }
void next(int x)
{
printf("%i\n", x);
dispatch[x/1000](x+1);
}
int main()
{
next(1);
return 0;
}