现在c语言都这样写了么

//
//  main.c
//  ctest
//
//  Created by liweijian on 13-3-18.
//  Copyright (c) 2013年 liweijian. All rights reserved.
//

#include <stdio.h>
#include <Block.h>

//闭包
typedef void(*func_t)();
func_t test()
{
    void func1()
    {
        printf("%s\n", __func__);
        printf("in func\n");
    };
    return func1;
}

//block1
#define test2() ({  \
    char _a = 'a'; \
    _a++;          \
    _a;            \
})


//block2
typedef int (^IntBlock)();
IntBlock MakeCounter(int start, int increment)
{
    __block int i = start;
    
    return Block_copy( ^ {
        int ret = i;
        i += increment;
        return ret;
    });
    
    
}

int main(int argc, const char * argv[])
{

  
    test()();
    
    int i = test2();
    printf("%d\n", i);
    
    
    IntBlock mycounter = MakeCounter(5, 2);
    printf("First call: %d\n", mycounter());
    printf("Second call: %d\n", mycounter());
    printf("Third call: %d\n", mycounter());
    
    /* because it was copied, it must also be released */
    Block_release(mycounter);
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值