首页 > 解决方案 > 在普通 C(msvc) 中模拟 lambdas - 递归 lambdas

问题描述

因此,我面临在 msvc 编译器(它不支持 gcc 扩展)上模仿纯 C 中的 lambda 定义的挑战——我想出了一个文件包含解决方案,它基本上反映了顶部的文件。它适用于大多数情况,但如果我想在我的 lambda 中包含一个 lambda:

#ifndef FIRSTPASS
#include <stdio.h>

//here comes your "nested" definitions
#define FIRSTPASS
#include "source.c"
#undef FIRSTPASS

main(){
#else
    int global = 2;
    int func() 
    {
        //define another "lambda" here
        printf("%d\n", global);
    }
#endif
#ifndef FIRSTPASS
    func();}
#endif

标签: clambdac-preprocessor

解决方案


推荐阅读