]> git.sur5r.net Git - cc65/blob - test/ref/return.c
Merge pull request #849 from polluks/patch-4
[cc65] / test / ref / return.c
1 /*
2   !!DESCRIPTION!! return values, implicit type conversion on return
3   !!ORIGIN!!      cc65 devel list
4   !!LICENCE!!     Public Domain
5 */
6
7 #include <stdio.h>
8 #include <stdlib.h>
9
10 unsigned char val_char=0x76;
11 unsigned int val_int=0x5678;
12 unsigned long val_long=0x12345678;
13
14 int test1_int_char(void)
15 {
16     return val_char;
17 }
18 int test1_int_int(void)
19 {
20     return val_int;
21 }
22
23 int test2_int_char(void)
24 {
25     return (int)val_char;
26 }
27 int test2_int_int(void)
28 {
29     return (int)val_int;
30 }
31
32 long test1_long_char(void)
33 {
34     return val_char;
35 }
36 long test1_long_int(void)
37 {
38     return val_int;
39 }
40 long test1_long_long(void)
41 {
42     return val_long;
43 }
44
45 long test2_long_char(void)
46 {
47     return (long)val_char;
48 }
49 long test2_long_int(void)
50 {
51     return (long)val_int;
52 }
53 long test2_long_long(void)
54 {
55     return (long)val_long;
56 }
57
58 #define dotest(_n,_a,_v) \
59     _n=_a; \
60     printf("%04lx %04lx,",(unsigned long)_n,(unsigned long)_v); \
61     if(_n!=_v) printf("failed\n"); \
62     else printf("ok\n")
63
64 int main(void)
65 {
66 int i;
67 unsigned long l;
68
69     printf("\nwithout cast:\n");
70
71     printf("return int\n");
72
73     dotest(i,test1_int_char(),0x76);
74     dotest(i,test1_int_int(),0x5678);
75
76     printf("return long\n");
77
78     dotest(l,test1_long_char(),0x76);
79     dotest(l,test1_long_int(),0x5678);
80     dotest(l,test1_long_long(),0x12345678);
81
82    printf("\nwith cast:\n");
83
84    printf("return int\n");
85
86     dotest(i,test2_int_char(),0x76);
87     dotest(i,test2_int_int(),0x5678);
88
89     printf("return long\n");
90
91     dotest(l,test2_long_char(),0x76);
92     dotest(l,test2_long_int(),0x5678);
93     dotest(l,test2_long_long(),0x12345678);
94
95     return 0;
96 }