Mercurial > hg > CbC > CbC_gcc
changeset 108:7ad14f446135
add CbC-example/rectypeTest/
author | Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Thu, 14 Jun 2012 20:30:24 +0900 |
parents | a3a2f64cf8f4 |
children | 78d3881f2882 |
files | CbC-examples/rectypeTest/struct2.cbc CbC-examples/rectypeTest/typedef2.cbc CbC-examples/rectypeTest/typedef3.cbc |
diffstat | 3 files changed, 78 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/CbC-examples/rectypeTest/struct2.cbc Thu Jun 14 20:30:24 2012 +0900 @@ -0,0 +1,33 @@ + +struct interface { + __code (*next)(); + __rectype child; + // __rectype *child; + // struct interface *child; +}; + +#include <stdio.h> +__code csA() +{ + printf("csA\n"); +} + +__code csB() +{ + printf("csB\n"); +} + +int main() +{ + struct interface p; + p.next = csA; + + struct interface pp; + pp.next = csB; + p.child = &pp; + + // goto p.child->next(); + goto p.child->next(); + + return 0; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/CbC-examples/rectypeTest/typedef2.cbc Thu Jun 14 20:30:24 2012 +0900 @@ -0,0 +1,24 @@ +typedef __code (*csPtr)(__rectype); + +//typedef __code (*csPtr)(__code(*p)()); +//typedef __code (csPtr)(__code(*p)()); // csPtr *p + +#include <stdio.h> +__code cs_end(csPtr p) +{ + printf("end\n"); +} + +__code cs(csPtr p) +{ + csPtr b; + goto p(b); + // goto p(3); // note: expected ‘void (*)()’ but argument is of type ‘int’ +} + +int main() { + csPtr p; + p = cs_end; + goto cs(p); + return 0; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/CbC-examples/rectypeTest/typedef3.cbc Thu Jun 14 20:30:24 2012 +0900 @@ -0,0 +1,21 @@ +typedef __code (*csPtr)(__rectype*); + +#include <stdio.h> +__code cs_end(csPtr *p) +{ + printf("end\n"); +} + +__code cs(csPtr p) +{ + csPtr *b; // <- This declaration please care. + goto p(b); + // goto p(3); // note: expected ‘void (**’ but argument is of type ‘int’ +} + +int main() { + csPtr p; + p = cs_end; + goto cs(p); + return 0; +}