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
|
/* castest.c */
/*
#define signedchar
#define bigints
*/
#define unsigchar
#define unsigshort
#define unsiglong
#define TEST(u,c) if ( (u) != (c) )\
{ printf( "u != c\n" ); ++bad; } ++possible
main()
{
int bad;
int possible;
char c;
#ifdef signedchar
signed char sc;
#endif
#ifdef unsigchar
unsigned char uc;
#endif
short s;
#ifdef unsigshort
unsigned short us;
#endif
int i;
unsigned u;
long l;
#ifdef unsiglong
unsigned long ul;
#endif
bad = possible = 0;
u = 0x1ff;
c = (char) u;
if ( c < 0 )
printf( "characters are signed\n" );
TEST((char)u,c);
i = (int)(char) u;
TEST(i,(int)c);
TEST((int)(char)u,i);
#ifdef signedchar
sc = (signed char) u;
if ( sc >= 0 )
printf( "??? signed char not signed\n" );
TEST((signed char)u,sc);
TEST((int)(signed char)u,(int)sc);
i = (int) sc;
TEST((int)(signed char)u,i);
#endif
#ifdef bigints
u = 0x1ffff;
s = (short) u;
TEST((short)u,s);
TEST((int)(short)u,(int)s);
i = (int) s;
TEST((int)(short)u,i);
#ifdef unsigshort
us = (unsigned short) u;
TEST((unsigned short)u,us);
TEST((int)(unsigned short)u,(int)us);
i = (int) us;
TEST((int)(unsigned short)u,i);
#endif
#endif
printf( "%d bad out of a possible %d\n", bad, possible );
}
|