view CbC-examples/test2.c @ 78:365b84b6fe04

more examples
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Tue, 20 Sep 2011 17:32:20 +0900
parents
children
line wrap: on
line source

#define __environment _CbC_environment
#define __return _CbC_return

#include <stdio.h>
int sender_bit;

__code (*ret)(int,void *);
void *env;

struct packet {
        int bit;
        char *msg;
        __code (*next)();
};

__code print_struct(struct packet pkt)
{
        printf("#0017:bit: %d\n", pkt.bit);
        printf("#0018:message: %s\n", pkt.msg);
        goto ret(0, env);
}

__code initSender(int init_bit, struct packet pkt)
{
        sender_bit = init_bit;
        pkt.next = print_struct;
        printf("#0026:initSender bit: %d\n", pkt.bit);
        printf("#0027:initSender message: %s\n", pkt.msg);
        printf("#0028:sender_bit: %d\n", sender_bit);
        goto print_struct(pkt);
}

int main(void)
{
        struct packet pkt;
        pkt.bit = 1;
        pkt.msg = "hogehoge";
        pkt.next = initSender;
        ret = __return;
        env = __environment;
        printf("#0040:main bit: %d\n", pkt.bit);
        printf("#0041:main message: %s\n", pkt.msg);
        goto initSender(0, pkt);
}