D
David RF
Hi friends, in this example:
#include <stdio.h>
struct Demo {
char *(*fn)(const char *, const char *);
char *value;
};
static void demo_set_fn(struct Demo *demo, char *(*fn)(const char *,
const char *))
{
demo->fn = fn;
}
static void demo_set_value(struct Demo *demo, char *value)
{
demo->value = value;
}
static char *demo_print(struct Demo *demo, const char *s)
{
return demo->fn(demo->value, s);
}
static char *dummy(const char *value, const char *s)
{
static char result[50];
sprintf(result, "%s %s\n", value, s);
return result;
}
int main(void)
{
struct Demo demo;
demo_set_fn(&demo, dummy);
demo_set_value(&demo, "Hello");
printf(demo_print(&demo, "world"));
return 0;
}
what's the difference between
demo_set_fn(&demo, dummy);
and
demo_set_fn(&demo, &dummy);
is & redundant?
both are valid?
#include <stdio.h>
struct Demo {
char *(*fn)(const char *, const char *);
char *value;
};
static void demo_set_fn(struct Demo *demo, char *(*fn)(const char *,
const char *))
{
demo->fn = fn;
}
static void demo_set_value(struct Demo *demo, char *value)
{
demo->value = value;
}
static char *demo_print(struct Demo *demo, const char *s)
{
return demo->fn(demo->value, s);
}
static char *dummy(const char *value, const char *s)
{
static char result[50];
sprintf(result, "%s %s\n", value, s);
return result;
}
int main(void)
{
struct Demo demo;
demo_set_fn(&demo, dummy);
demo_set_value(&demo, "Hello");
printf(demo_print(&demo, "world"));
return 0;
}
what's the difference between
demo_set_fn(&demo, dummy);
and
demo_set_fn(&demo, &dummy);
is & redundant?
both are valid?