📄 cq.c
字号:
return total;
}
s244(pd0)
struct defs *pd0;
{
double a[8];
int rc, lrc, j;
static char s244er[] = "s244,er%d\n";
static char qs244[8] = "s244 ";
char *ps, *pt;
ps = qs244;
pt = pd0->rfs;
while(*pt++ = *ps++);
rc = 0;
lrc = 0;
/* Unfortunately, there's not a lot we can do with floating constants.
We can check to see that the various representations can be com-
piled, that the conversion is such that they yield the same hard-
ware representations in all cases, and that all representations
thus checked are double precision. */
a[0] = .1250E+04;
a[1] = 1.250E3;
a[2] = 12.50E02;
a[3] = 125.0e+1;
a[4] = 1250e00;
a[5] = 12500.e-01;
a[6] = 125000e-2;
a[7] = 1250.;
lrc = 0;
for (j=0; j<7; j++) if(a[j] != a[j+1]) lrc = 1;
if(lrc != 0) {
if(pd0->flgd != 0) printf(s244er,1);
rc = rc+1;
}
if ( (sizeof .1250E+04 ) != sizeof(double)
|| (sizeof 1.250E3 ) != sizeof(double)
|| (sizeof 12.50E02 ) != sizeof(double)
|| (sizeof 1.250e+1 ) != sizeof(double)
|| (sizeof 1250e00 ) != sizeof(double)
|| (sizeof 12500.e-01) != sizeof(double)
|| (sizeof 125000e-2 ) != sizeof(double)
|| (sizeof 1250. ) != sizeof(double)){
if(pd0->flgd != 0) printf(s244er,2);
rc = rc+2;
}
return rc;
}
s25(pd0)
struct defs *pd0;
{
char *s, *s2;
int rc, lrc, j;
static char s25er[] = "s25,er%d\n";
static char qs25[8] = "s25 ";
char *ps, *pt;
ps = qs25;
pt = pd0->rfs;
while(*pt++ = *ps++);
rc = 0;
/* A string is a sequence of characters surrounded by double
quotes, as in "...". */
s = "...";
/* A string has type "array of characters" and storage class
static and is initialized with the given characters. */
if ( s[0] != s[1] || s[1] != s[2]
|| s[2] != '.' ) {
rc = rc+1;
if(pd0->flgd != 0) printf(s25er,1);
}
/* The compiler places a null byte \0 at the end of each string
so the program which scans the string can find its end. */
if( s[3] != '\0' ){
rc = rc+4;
if(pd0->flgd != 0) printf(s25er,4);
}
/* In a string, the double quote character " must be preceded
by a \. */
if( ".\"."[1] != '"' ){
rc = rc+8;
if(pd0->flgd != 0) printf(s25er,8);
}
/* In addition, the same escapes described for character constants
may be used. */
s = "\n\t\b\r\f\\\'";
if( s[0] != '\n'
|| s[1] != '\t'
|| s[2] != '\b'
|| s[3] != '\r'
|| s[4] != '\f'
|| s[5] != '\\'
|| s[6] != '\'' ){
rc = rc+16;
if( pd0->flgd != 0) printf(s25er,16);
}
/* Finally, a \ and an immediately following newline are ignored */
s2 = "queep!";
s = "queep!";
lrc = 0;
for (j=0; j<sizeof "queep!"; j++) if(s[j] != s2[j]) lrc = 1;
if (lrc != 0){
rc = rc+32;
if(pd0->flgd != 0) printf(s25er,32);
}
return rc;
}
s26(pd0) /* 2.6 Hardware Characteristics */
struct defs *pd0;
{
static char qs26[8] = "s26 ";
char *ps, *pt;
char c0, c1;
float temp, one, delta;
double tempd, oned;
static char s[] = "%3d bits in %ss.\n";
static char s2[] = "%e is the least number that can be added to 1. (%s).\n";
ps = qs26;
pt = pd0->rfs;
while(*pt++ = *ps++);
/* Here, we shake the machinery a little to see what falls
out. First, we find out how many bits are in a char. */
pd0->cbits = 0;
c0 = 0;
c1 = 1;
while(c0 != c1) {
c1 = c1<<1;
pd0->cbits = pd0->cbits+1;
}
/* That information lets us determine the size of everything else. */
pd0->ibits = pd0->cbits * sizeof(int);
pd0->sbits = pd0->cbits * sizeof(short);
pd0->lbits = pd0->cbits * sizeof(long);
pd0->ubits = pd0->cbits * sizeof(unsigned);
pd0->fbits = pd0->cbits * sizeof(float);
pd0->dbits = pd0->cbits * sizeof(double);
/* We have now almost reconstructed the table in section 2.6, the
exception being the range of the floating point hardware.
Now there are just so many ways to conjure up a floating point
representation system that it's damned near impossible to guess
what's going on by writing a program to interpret bit patterns.
Further, the information isn't all that useful, if we consider
the fact that machines that won't handle numbers between 10**30
and 10**-30 are very hard to find, and that people playing with
numbers outside that range have a lot more to worry about than
just the capacity of the characteristic.
A much more useful measure is the precision, which can be ex-
pressed in terms of the smallest number that can be added to
1. without loss of significance. We calculate that here, for
float and double. */
one = 1.;
delta = 1.;
temp = 0.;
while(temp != one) {
temp = one+delta;
delta = delta/2.;
}
pd0->fprec = delta * 4.;
oned = 1.;
delta = 1.;
tempd = 0.;
while(tempd != oned) {
tempd = oned+delta;
delta = delta/2.;
}
pd0->dprec = delta * 4.;
/* Now, if anyone's interested, we publish the results. */
if(pd0->flgm != 0) {
printf(s,pd0->cbits,"char");
printf(s,pd0->ibits,"int");
printf(s,pd0->sbits,"short");
printf(s,pd0->lbits,"long");
printf(s,pd0->ubits,"unsigned");
printf(s,pd0->fbits,"float");
printf(s,pd0->dbits,"double");
printf(s2,pd0->fprec,"float");
printf(s2,pd0->dprec,"double");
}
/* Since we are only exploring and perhaps reporting, but not
testing any features, we cannot return an error code. */
return 0;
}
int extvar;
s4(pd0) /* 4. What's in a name? */
struct defs *pd0;
{
static char s4er[] = "s4,er%d\n";
static char qs4[8] = "s4 ";
char *ps, *pt;
int j, rc;
short sint; /* short integer, for size test */
int pint; /* plain */
long lint; /* long */
unsigned target;
unsigned int mask;
rc = 0;
ps = qs4;
pt = pd0->rfs;
while(*pt++ = *ps++);
/* There are four declarable storage classes: automatic,
static, external, and register. Automatic variables have
been dealt with extensively thus far, and will not be specif-
ically treated in this section. Register variables are treated
in section s81.
Static variables are local to a block, but retain their
values upon reentry to a block, even after control has left
the block. */
for (j=0; j<3; j++)
if(svtest(j) != zero()){
rc = 1;
if(pd0->flgd != 0) printf(s4er,1);
}
;
/* External variables exist and retain their values throughout
the execution of the entire program, and may be used for comm-
unication between functions, even separately compiled functions.
*/
setev();
if(testev() != 0){
rc=rc+2;
if(pd0->flgd != 0) printf(s4er,2);
}
/*
Characters have been tested elsewhere (in s243).
Up to three sizes of integer, declared short int, int, and
long int, are available. Longer integers provide no less storage
than shorter ones, but implementation may make either short
integers, or long integers, or both, equivalent to plain
integers.
*/
if(sizeof lint < sizeof pint || sizeof pint < sizeof sint){
rc = rc+4;
if(pd0->flgd != 0) printf(s4er,4);
}
/* Unsigned integers, declared unsigned, obey the laws of
arithmetic modulo 2**n, where n is the number of bits in the
implementation */
target = ~0U;
mask = 1;
for(j=0; j<(sizeof target)*pd0->cbits; j++){
mask = mask⌖
target = target>>1;
}
if(mask != 1 || target != 0){
rc = rc+8;
if(pd0->flgd != 0) printf(s4er,8);
}
return rc;
}
svtest(n)
int n;
{
static k;
int rc;
switch (n) {
case 0: k = 1978;
rc = 0;
break;
case 1: if(k != 1978) rc = 1;
else{
k = 1929;
rc = 0;
}
break;
case 2: if(k != 1929) rc = 1;
else rc = 0;
break;
}
return rc;
}
zero(){ /* Returns a value of zero, possibly */
static k; /* with side effects, as it's called */
int rc; /* alternately with svtest, above, */
k = 2; /* and has the same internal storage */
rc = 0; /* requirements. */
return rc;
}
testev(){
if(extvar != 1066) return 1;
else return 0;
}
s61(pd0) /* Characters and integers */
struct defs *pd0;
{
static char s61er[] = "s61,er%d\n";
static char qs61[8] = "s61 ";
short from, shortint;
long int to, longint;
int rc, lrc;
int j;
char fromc, charint;
char *wd, *pc[6];
static char upper_alpha[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
static char lower_alpha[] = "abcdefghijklmnopqrstuvwxyz";
static char numbers[] = "0123456789";
static char special_characters[] = "~!\"#%&()_=-^|{}[]+;*:<>,.?/";
static char extra_special_characters[] = "\n\t\b\r\f\\\'";
static char blank_and_NUL[] = " \0";
char *ps, *pt;
ps = qs61;
pt = pd0->rfs;
rc = 0;
while (*pt++ = *ps++);
/* A character or a short integer may be used wherever
an integer may be used. In all cases, the value is converted
to integer. This principle is extensively used throughout this
program, and will not be explicitly tested here. */
/* Conversion of a shorter integer to a longer always
involves sign extension. */
from = -19;
to = from;
if(to != -19){
rc = rc+1;
if(pd0->flgd != 0) printf(s61er,1);
}
/* It is guaranteed that a member of the standard char-
acter set is nonnegative. */
pc[0] = upper_alpha;
pc[1] = lower_alpha;
pc[2] = numbers;
pc[3] = special_characters;
pc[4] = extra_special_characters;
pc[5] = blank_and_NUL;
lrc = 0;
for (j=0; j<6; j++)
while(*pc[j]) if(*pc[j]++ < 0) lrc =1;
if(lrc != 0){
rc=rc+2;
if(pd0->flgd != 0) printf(s61er,2);
}
/* When a longer integer is converted to a shorter or
to a char, it is truncated on the left; excess bits are
simply discarded. */
longint = 1048579; /* =2**20+3 */
shortint = longint;
charint = longint;
if((shortint != longint && shortint != 3) ||
(charint != longint && charint != 3)) {
rc = rc+8;
if(pd0->flgd != 0) printf(s61er,8);
}
return rc;
}
s626(pd0) /* 6.2 Float and double */
/* 6.3 Floating and integral */
/* 6.4 Pointers and integers */
/* 6.5 Unsigned */
/* 6.6 Arithmetic conversions */
struct defs *pd0;
{
static char s626er[] = "s626,er%d\n";
static char qs626[8] = "s626 ";
int rc;
char *ps, *pt;
float eps, f1, f2, f3, f4, f;
long lint1, lint2, l, ls;
char c, t[28], t0;
short s;
int is, i, j;
unsigned u, us;
double d, ds;
ps = qs626;
pt = pd0->rfs;
rc = 0;
while (*pt++ = *ps++);
/* Conversions of integral values to floating type are
well-behaved. */
f1 = 1.;
lint1 = 1.;
lint2 = 1.;
for(j=0;j<pd0->lbits-2;j++){
f1 = f1*2;
lint2 = (lint2<<1)|lint1;
}
f2 = lint2;
f1 = (f1-f2)/f1;
if(f1>2.*pd0->fprec){
rc = rc+2;
if(pd0->flgd != 0) printf(s626er,2);
}
/* Pointer-integer combinations are discussed in s74,
"Additive operators". The unsigned-int combination
appears below. */
c = 125;
s = 125;
i = 125; is = 15625;
u = 125; us = 15625;
l = 125; ls = 15625;
f = 125.;
d = 125.; ds = 15625.;
for(j=0;j<28;j++) t[j] = 0;
if(c*c != is) t[ 0] = 1;
if(s*c != is) t[ 1] = 1;
if(s*s != is) t[ 2] = 1;
if(i*c != is) t[ 3] = 1;
if(i*s != is) t[ 4] = 1;
if(i*i != is) t[ 5] = 1;
if(u*c != us) t[ 6] = 1;
if(u*s != us) t[ 7] = 1;
if(u*i != us) t[ 8] = 1;
if(u*u != us) t[ 9] = 1;
if(l*c != ls) t[10] = 1;
if(l*s != ls) t[11] = 1;
if(l*i != ls) t[12] = 1;
if(l*u != us) t[13] = 1;
if(l*l != ls) t[14] = 1;
if(f*c != ds) t[15] = 1;
if(f*s != ds) t[16] = 1;
if(f*i != ds) t[17] = 1;
if(f*u != ds) t[18] = 1;
if(f*l != ds) t[19] = 1;
if(f*f != ds) t[20] = 1;
if(d*c != ds) t[21] = 1;
if(d*s != ds) t[22] = 1;
if(d*i != ds) t[23] = 1;
if(d*u != ds) t[24] = 1;
if(d*l != ds) t[25] = 1;
if(d*f != ds) t[26] = 1;
if(d*d != ds) t[27] = 1;
t0 = 0;
for(j=0; j<28; j++) t0 = t0+t[j];
if(t0 != 0){
rc = rc+4;
if(pd0->flgd != 0){
printf(s626er,4);
printf(" key=");
for(j=0;j<28;j++) printf("%d",t[j]);
printf("\n");
}
}
/* When an unsigned integer is converted to long,
the value of the result is the same numerically
as that of the unsigned integer. */
l = (unsigned)0100000;
if((long)l > (unsigned)0100000){
rc = rc+8;
if(pd0->flgd != 0) printf(s626er,8);
}
return rc;
}
s71(pd0) /* 7.1 Primary expressions */
struct defs *pd0;
{
static char s71er[] = "s71,er%d\n";
static char qs71[8] = "s71 ";
int rc;
char *ps, *pt;
static char q = 'q';
int x[10], McCarthy(), clobber(), a, b, *p;
ps = qs71;
pt = pd0->rfs;
rc = 0;
while (*pt++ = *ps++);
/* Testing of expressions and operators is quite complicated,
because (a) problems are apt to surface in queer combinations
of operators and operands, rather than in isolation,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -