代码 ({ //函数实现 函数名称; })
#include <stdio.h>
#include <malloc.h>
#define action_lambda(function_body) \
({void lambda_func function_body lambda_func;})
#define func_lambda(return_type, function_body) \
({return_type lambda_func function_body lambda_func;})
typedef void (*Action)(char** message);
void Initial(Action options);
static char* g_opts = NULL;
int main(int argc, char **argv)
{
char* msgs = "test";
// 调用
Initial(action_lambda((char** msg){ *msg = msgs; printf("g_opts = %s.", g_opts); }));
return 0;
}
void Initial(Action options)
{
options(&g_opts);
}
标签:function,内嵌,GCC,void,body,char,func,Lambda,lambda
From: https://www.cnblogs.com/microestc/p/17494279.html