]> git.sur5r.net Git - cc65/blob - test/val/cq715.c
added tests as prepared by oliver
[cc65] / test / val / cq715.c
1 /*
2   !!DESCRIPTION!! C-Manual Chapter 7.15: Comma operator
3   !!ORIGIN!!      LCC 4.1 Testsuite
4   !!LICENCE!!     own, freely distributeable for non-profit. read CPYRIGHT.LCC
5 */
6
7 struct defs {
8      int cbits;          /* No. of bits per char           */
9      int ibits;          /*                 int            */
10      int sbits;          /*                 short          */
11      int lbits;          /*                 long           */
12      int ubits;          /*                 unsigned       */
13      int fbits;          /*                 float          */
14      int dbits;          /*                 double         */
15      #ifndef NO_FLOATS
16         float fprec;        /* Smallest number that can be    */
17         float dprec;        /* significantly added to 1.      */
18      #endif
19      int flgs;           /* Print return codes, by section */
20      int flgm;           /* Announce machine dependencies  */
21      int flgd;           /* give explicit diagnostics      */
22      int flgl;           /* Report local return codes.     */
23      int rrc;            /* recent return code             */
24      int crc;            /* Cumulative return code         */
25      char rfs[8];        /* Return from section            */
26 };
27
28      int lbits;          /*                 long           */
29      int ubits;          /*                 unsigned       */
30      int fbits;          /*                 float          */
31      int dbits;          /*                 double         */
32      #ifndef NO_FLOATS
33         float fprec;        /* Smallest number that can be    */
34         float dprec;        /* significantly added to 1.      */
35      #endif
36      int flgs;           /* Print return codes, by section */
37      int flgm;           /* Announce machine dependencies  */
38      int flgd;           /* give explicit diagnostics      */
39      int flgl;           /* Report local return codes.     */
40      int rrc;            /* recent return code             */
41      int crc;            /* Cumulative return code         */
42      char rfs[8];        /* Return from section            */
43
44 /*#include "cq26.c"*/ /* hardware check */
45 #ifdef NO_IMPLICIT_FUNC_PROTOTYPES
46 s715f(int x,int y,int z);
47 #endif
48
49 #ifndef NO_OLD_FUNC_DECL
50 s715(pd0)          /*  7.15 Comma operator     */
51 struct defs *pd0;
52 {
53 #else
54 int s715(struct defs *pd0) {
55 #endif
56    static char s715er[] = "s715,er%d\n";
57    static char qs715[8] = "s715   ";
58    int rc;
59    char *ps, *pt;
60    int a, t, c, i;
61    a = c = 0;
62    ps = qs715;
63    pt = pd0->rfs;
64    rc = 0;
65    while (*pt++ = *ps++);
66
67         /* A pair of expressions separated by a comma is
68         evaluated left to right and the value of the left
69         expression is discarded.
70                                                                 */
71    i = 1;
72    if( i++,i++,i++,i++,++i != 6 ){
73      if(pd0->flgd != 0) printf(s715er,1);
74      rc = rc+1;
75    }
76
77         /* In contexts where the comma is given a special mean-
78         ing, for example in a list of actual arguments to
79         functions (sic) and lists of initializers, the comma
80         operator as described in this section can only appear
81         in parentheses; for example
82
83                 f( a, (t=3, t+2), c)
84
85         has three arguments, the second of which has the
86         value 5.
87                                                                 */
88
89    if(s715f(a, (t=3, t+2), c) != 5){
90      if(pd0->flgd != 0) printf(s715er,2);
91      rc = rc+2;
92    }
93    return rc;
94 }
95 s715f(x,y,z)
96 int x, y, z;
97 {
98    return y;
99 }
100
101 /*********************************************************************************************
102  the main loop that launches the sections
103 *********************************************************************************************/
104
105 #ifndef NO_TYPELESS_STRUCT_PTR
106         int section(int j,struct* pd0){
107 #else
108         int section(int j,void* pd0){
109 #endif
110         switch(j){
111                 /*case 0: return s26(pd0);*/
112                 case 0: return s715(pd0);
113         }
114 }
115
116 #define cq_sections 1
117
118 /*
119         C REFERENCE MANUAL (main)
120 */
121
122 #ifndef NO_OLD_FUNC_DECL
123 main(n,args)
124 int n;
125 char **args;
126 {
127 #else
128 int main(int n,char **args) {
129 #endif
130
131 int j;
132 static struct defs d0, *pd0;
133         
134    d0.flgs = 1;          /* These flags dictate            */
135    d0.flgm = 1;          /*     the verbosity of           */
136    d0.flgd = 1;          /*         the program.           */
137    d0.flgl = 1;
138
139    pd0 = &d0;
140
141    for (j=0; j<cq_sections; j++) {
142      d0.rrc=section(j,pd0);
143      d0.crc=d0.crc+d0.rrc;
144      if(d0.flgs != 0) printf("Section %s returned %d.\n",d0.rfs,d0.rrc);
145    }
146
147    if(d0.crc == 0) printf("\nNo errors detected.\n");
148    else printf("\nFailed.\n");
149
150    return d0.crc;
151 }