Mercurial > hg > CbC > CbC_examples
view test_return.c @ 5:90e6146d24cd
fix stack1.c
author | Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp> |
---|---|
date | Wed, 22 Oct 2014 19:02:57 +0900 |
parents | 35d6eabeadb0 |
children |
line wrap: on
line source
#include<stdio.h> #ifdef CLANG #define _CbC_return __return #define _CbC_environment __environment #endif #if 0 typedef float testtype; testtype good = 33.3f; testtype bad = 0.0f; void print_testtype(testtype t) { printf("return value = %2.3f good=%2.3f,bad=%2.3f\n", t,good,bad); } #elif 1 typedef char testtype; testtype good = 33; testtype bad = 0; void print_testtype(testtype t) { printf("return value = %d, good=%d,bad=%d\n", t,good,bad); } #elif 0 typedef double testtype; testtype good = 333.3; testtype bad = 0.00; void print_testtype(testtype t) { printf("return value = %3.3lf, good=%3.3lf,bad=%3.3lf\n", t,good,bad); } #elif 0 typedef struct { int a; float b; int c[4]; } testtype; testtype good = {33, 33.3, {4,4,4,4}}; testtype bad = {0, 00.0, {0,0,0,0}}; void print_testtype(testtype t) { printf( "return value = {\n" " a = %d\n" " b = %2.3f\n" " c = { %d, %d, %d, %d }" "}\n", t.a, t.b, t.c[0],t.c[1],t.c[2],t.c[3]); } #else typedef int testtype; testtype good = 33; testtype bad = 0; void print_testtype(testtype t) { printf("return value = %d, good=%d,bad=%d\n", t,good,bad); } #endif typedef void (*RET_FUNC)(testtype, void *); void g(RET_FUNC func) { func(good, NULL); } testtype f_cbc() { void *ret; ret = _CbC_return; printf("f0: fp = %p\n", __builtin_frame_address(0)); printf("__return_func = %p\n", ret); g(ret); printf("not good\n"); return bad; } int main(int argc, char **argv) { testtype t; printf("main before: fp = %p\n", __builtin_frame_address(0)); t = f_cbc(); print_testtype(t); printf("main after: fp = %p\n", __builtin_frame_address(0)); }