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