Seebs said:
You can't do optional-argument macros.
Furthermore, don't do this. Several reasons, not the least of which is
that you're counting backwards which will usually surprise people, and
you should never hide simple basic syntax behind macros.
C99 added variadic macros. You *might* be able to do something like:
#define dofor(count, ...) /* something */
so at least both dofor(512, i) and dofor(512) would be legal. But I
can't think of a way to make this work for what the OP is asking about
(not that I tried very hard).
To the OP: If you're going to do this, at least use all-caps for the
macro name. (The convention of using all-caps for macro names is
intended to make them stand out, so it's obvious to the reader that
something strange is going on.)
For that matter, there's not that much benefit in using a single name
for both. If you want the loop variable name to default to i (yours
defaults to f, but i makes more sense), you could just write:
#define DOFOR(count, var) for ((var) = (count); (var) != 0; (var)--)
#define DOFORI(count) for (i = (count); i != 0; i--)
Or, if you can depend on having a C99 compiler, or at least one that
supports declarations in for loops as an extension:
#define DOFOR(count, var) for (int var = (count); (var) != 0; (var)--)
#define DOFORI(count) for (int i = (count); i != 0; i--)
You have to know how many arguments you're using when you write the
call; using distinct names isn't much of an added burden.
But these are all improvements on a bad idea. A better solution is
just to write ordinary for loops; they're going to be much more
legible to anyone reading your code (including you six months
from now).