Ivan wrote:
Hi,
I have a function that takes, say, two varialbles:
double g_fn(const double x, const double t)
{
..............
}
In another function I want to use g_fn as an single-parameter
function, like
gg_fn(x)
Is there a shorter or better way than to redefine
double gg_fn(x)
{
extern t;
return g_fn(x,t);
}
and calling "t" as a global parameter?
Not really, no. C doesn't support higher-order functions [1].
Messing around with stdargs is /possible/ but almost certainly
won't be worth it [2].
If you routinely want to do this, then you could define a
struct with a [pointer to a] function and frozen argument in it,
and then have a `call` function so that
call( fn, y ) is fn->f( fn->x, y )
However, C's type system isn't very helpful here, since you'd
need either a different struct (and version of `call`) for each
function signature, or lots of messing around with void*s.
Either pick a different language, or tell us what you're trying
to do, and we'll see if there's a more C-friendly way of doing
it.
[1] Well, it does just a /tiny/ bit - function pointers.
[2] Every function that plays this game will need to have
an early argument to say how many arguments you've supplied,
and pick up the "extra" arguments using the valist machinery.
--
Chris "electric hedgehog" Dollin
"Go not to the Elves for counsel, for they will answer both no and yes"
/The Lord of the Rings/