【发布时间】:2018-02-12 15:13:06
【问题描述】:
typedef logs_t(*logs_t)(char *);
logs_t logs(char *s) {
printf("%s", s);
fflush(0);
return &logs;
}
错误:
log.c:1:17: warning: type specifier missing, defaults to 'int' [-Wimplicit-int]
typedef logs_t(*logs_t)(char *);
^
log.c:1:9: warning: type specifier missing, defaults to 'int' [-Wimplicit-int]
typedef logs_t(*logs_t)(char *);
~~~~~~~ ^
log.c:1:15: fatal error: function cannot return function type 'int (char *)'
typedef logs_t(*logs_t)(char *);
^
2 warnings and 1 error generated.
我想在这里实现的是将调用链接到logs:
logs("a")("b");
【问题讨论】:
-
嗯,简单地说 - 你不能。不过你可以返回
struct... -
@JulienLopez 这不是柯里化。柯里化是让一个函数修复另一个函数的参数。这里OP只想得到一个定点。
-
对于任何类型
T和函数T f(void);,表达式&f将是T (*)(void)类型,这与T不兼容,不管T。您可以破解一些可能适用于一些严肃的铸造体操的东西,但它不允许像您的示例中那样进行链式函数调用。
标签: c