struct / union in initializer, RFE #901.
[sdcc.git] / sdcc / support / regression / tests / structreturn.c.in
blobdc153be5ff1a44a4a531cf80851f4b4c4ea76143
1 /* Test return of struct / union
3 type: char, int, long, long long
5 */
7 #include <testfwk.h>
9 #ifndef __SDCC_pdk14 // Lack of memory
10 #if !defined(__SDCC_ds390) && !defined(__SDCC_ds390) && !defined(__SDCC_hc08) && !defined(__SDCC_s08) && !defined(__SDCC_mos6502) && !defined(__SDCC_mos65c02) // struct return not yet supported
11 struct s
13 {type} a;
14 {type} b;
17 union u
19 unsigned char a;
20 {type} b;
23 struct s f(void)
25 struct s r;
26 r.a = 1;
27 r.b = 2;
28 return(r);
31 union u g(void)
33 union u r;
34 r.a = 1;
35 return(r);
38 int g1(void)
40 struct s r;
41 r = f(); // Assignment of returned struct
42 return r.a + r.b;
45 int g2(void)
47 return f().a + f().b; // Access to member of returned struct
50 int h1(void)
52 union u r;
53 r = g(); // Assignment of returned struct
54 return r.a + 1;
57 int h2(void)
59 return g().a + 1; // Access to member of returned struct
61 #endif
62 #endif
64 void testRet (void)
66 #if !defined(__SDCC_ds390) && !defined(__SDCC_ds390) && !defined(__SDCC_hc08) && !defined(__SDCC_s08) && !defined(__SDCC_mos6502) && !defined(__SDCC_mos65c02) // struct return not yet supported
67 #ifndef __SDCC_pdk14 // Lack of memory
68 ASSERT (g1() == 3);
69 ASSERT (g2() == 3);
70 ASSERT (h1() == 2);
71 ASSERT (h2() == 2);
72 #endif
73 #endif