File: return.c

package info (click to toggle)
cc65 2.19-2
  • links: PTS
  • area: main
  • in suites: forky, sid, trixie
  • size: 20,268 kB
  • sloc: ansic: 117,151; asm: 66,339; pascal: 4,248; makefile: 1,009; perl: 607
file content (96 lines) | stat: -rw-r--r-- 1,614 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/*
  !!DESCRIPTION!! return values, implicit type conversion on return
  !!ORIGIN!!      cc65 devel list
  !!LICENCE!!     Public Domain
*/

#include <stdio.h>
#include <stdlib.h>

unsigned char val_char=0x76;
unsigned int val_int=0x5678;
unsigned long val_long=0x12345678;

int test1_int_char(void)
{
    return val_char;
}
int test1_int_int(void)
{
    return val_int;
}

int test2_int_char(void)
{
    return (int)val_char;
}
int test2_int_int(void)
{
    return (int)val_int;
}

long test1_long_char(void)
{
    return val_char;
}
long test1_long_int(void)
{
    return val_int;
}
long test1_long_long(void)
{
    return val_long;
}

long test2_long_char(void)
{
    return (long)val_char;
}
long test2_long_int(void)
{
    return (long)val_int;
}
long test2_long_long(void)
{
    return (long)val_long;
}

#define dotest(_n,_a,_v) \
    _n=_a; \
    printf("%04lx %04lx,",(unsigned long)_n,(unsigned long)_v); \
    if(_n!=_v) printf("failed\n"); \
    else printf("ok\n")

int main(void)
{
int i;
unsigned long l;

    printf("\nwithout cast:\n");

    printf("return int\n");

    dotest(i,test1_int_char(),0x76);
    dotest(i,test1_int_int(),0x5678);

    printf("return long\n");

    dotest(l,test1_long_char(),0x76);
    dotest(l,test1_long_int(),0x5678);
    dotest(l,test1_long_long(),0x12345678);

   printf("\nwith cast:\n");

   printf("return int\n");

    dotest(i,test2_int_char(),0x76);
    dotest(i,test2_int_int(),0x5678);

    printf("return long\n");

    dotest(l,test2_long_char(),0x76);
    dotest(l,test2_long_int(),0x5678);
    dotest(l,test2_long_long(),0x12345678);

    return 0;
}