Subversion Repositories tendra.SVN

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 7u83 1
<!-- Crown Copyright (c) 1998 -->
2
<HTML>
3
<HEAD>
4
<TITLE>C Checker Reference Manual: Integral Type Specification</TITLE>
5
</HEAD>
6
<BODY TEXT="#000000" BGCOLOR="#FFFFFF" LINK="#0000FF" VLINK="#400080" ALINK="#FF0000">
7
<A NAME=S127>
8
<H1>C Checker Reference Manual</H1>
9
<H3>January 1998</H3>
10
<A HREF="tdfc18.html"><IMG SRC="../images/next.gif" ALT="next section"></A>
11
<A HREF="tdfc16.html"><IMG SRC="../images/prev.gif" ALT="previous section"></A>
12
<A HREF="tdfc1.html"><IMG SRC="../images/top.gif" ALT="current document"></A>
13
<A HREF="../index.html"><IMG SRC="../images/home.gif" ALT="TenDRA home page">
14
</A>
15
<IMG SRC="../images/no_index.gif" ALT="document index"><P>
16
<HR>
17
<DL>
18
<DT><A HREF="#S128"><B>C.1 </B> - Specifying integer literal types</A><DD>
19
<DT><A HREF="#S129"><B>C.2 </B> - The Portability Table</A><DD>
20
</DL>
21
 
22
<HR>
23
<H1>C  Integral Type Specification</H1>
24
<A NAME=S128>
25
<HR><H2>C.1  <A NAME=2>Specifying integer literal types</H2>
26
The integer literal pragmas are used to define the method of computing
27
the type of an integer literal. Integer literals cannot be used in
28
a program unless the class to which they belong has been described
29
using an integer literal pragma. Each built-in checking mode includes
30
some integer literal pragmas describing the semantics appropriate
31
for that mode. If these built-in modes are inappropriate, then the
32
user must describe the semantics using the pragma below: <P>
33
<PRE>
34
	#pragma integer literal <EM>literal_class lit_class_type_list</EM>
35
</PRE>
36
The <EM>literal_class</EM> identifies the type of literal integer
37
involved. The possibilities are: <P>
38
<UL>
39
<LI><CODE>decimal</CODE>
40
<LI><CODE>octal</CODE>
41
<LI><CODE>hexadecimal</CODE>
42
</UL>
43
Each of these types can optionally be followed by <CODE>unsigned</CODE>
44
and/or <CODE>long</CODE> to specify an unsigned and/or long type respectively.
45
<P>
46
The values of the integer literals of any particular class are divided
47
into contiguous sub-ranges specified by the <CODE>lit_class_type_list</CODE>
48
which takes the form below: <P>
49
<PRE>
50
    <EM>lit_class_type_list</EM>
51
	*<EM>int_type_spec</EM>
52
	    <EM>integer_constant int_type_spec</EM> | <EM>lit_class_type_list</EM>
53
	<EM>int_type_spec</EM> :
54
	    : <EM>type_name</EM>
55
	    * warning<SUB><I>opt</I></SUB> : <EM>identifier</EM>
56
	    ** :
57
</PRE>
58
The first integer constant, i1 say, identifies the range [0,i1], the
59
second, i2 say, identifies the range [i1+1,i2]. The symbol * specifies
60
the unlimited range upwards from the last integer constant. Each integer
61
constant must be strictly greater than its predecessor. <P>
62
Associated with each sub-range is an <EM>int_type_spec</EM> which
63
is either a type, a procedure token identifier with an optional warning
64
(see G.9)or a failure. For each sub-range: <P>
65
<UL>
66
<LI>If the <EM>int_type_spec</EM> is a type name, then it must be
67
an integral type and specifies the type associated with literals in
68
that sub-range. <P>
69
<LI>If the <CODE>int_type_spec</CODE> is an identifier, then the type
70
of integer is computed by a procedure token of that name which takes
71
the integer value as a parameter and delivers its type. The procedure
72
token must have been declared previously as 
73
<PRE>
74
	#pragma token PROC ( VARIETY ) VARIETY
75
</PRE>
76
Since the type of the integer is computed by a procedure token which
77
may be implemented differently on different targets, there is the
78
option of producing a warning whenever the token is applied.<P>
79
<LI>If the <EM>int_type_spec</EM> is **, then any integer literal
80
lying in the associated sub-range will cause the checker to raise
81
an error.<P>
82
</UL>
83
For example:<P>
84
<PRE>
85
	#pragma integer literal decimal 0x7fff : int | 0x7fffffff : long | * : unsigned long
86
</PRE>
87
divides unsuffixed decimal literals into three ranges: literals in
88
the range [0, 0x7fff] are of type int, integer literals in the range
89
[0x7fff, 0x7fffffff] are of type long and the remainder are of type
90
unsigned long.<P>
91
There are four pre-defined procedure tokens supplied with the compiler
92
which are used in the startup files to provide the default specification
93
for integer literals: <P>
94
<UL>
95
<LI><CODE>~lit_int</CODE> is the external identification of a token
96
that returns the integer type according to the rules of ISO C for
97
an unsuffixed decimal;<P>
98
<LI><CODE>~lit_hex </CODE>is the external identification of a token
99
that returns the integer type according to the rules of ISO C for
100
an unsuffixed hexadecimal; <P>
101
<LI><CODE>~lit_unsigned</CODE> is the external identification of a
102
token that returns the integer type according to the rules of ISO
103
C for integers suffixed by U only; <P>
104
<LI><CODE>~lit_long</CODE> is the external identification of a token
105
that returns the integer type according to the rules of ISO C for
106
integers suffixed by L only. <P>
107
</UL>
108
<A NAME=S129>
109
<HR><H2>C.2  The Portability Table</H2>
110
The portability table is used by the checker to describe the minimum
111
assumptions about the representation of the integral types. It contains
112
information on the minimum integer sizes and the minimum range of
113
values that can be represented by each integer type.<P>
114
Two built-in portability tables are provided. The default reflects
115
the minimal requirements laid down in the ISO C standard. The 32-bit
116
portability table (specified by the passing the -Y32bit option to
117
tchk) reflects the implementation on most modern 32 bit machines.
118
These tables are shown below.<P>
119
<B>ISO/ANSI Minimum Requirements Portability Table (default)</B><BR>
120
<CENTER>
121
<IMG SRC="table2.gif">
122
</CENTER>
123
<P>
124
<B>32 bit Portability table (specified by -Y32bit option)</B><BR>
125
<CENTER>
126
<IMG SRC="table3.gif">
127
</CENTER>
128
<P>
129
The decimal integer associated with each of <EM>char_bits</EM>, <EM>short_bits
130
</EM>, <EM>int_bits</EM> and <EM>long_bits</EM> gives the minimum
131
number of bits in the representation of each integer type on all target
132
machines. For example, if <EM>int_bits</EM> is set to 32 the compiler
133
will perform its checks in the knowledge that the program will not
134
be used on a machine whose int types are represented by 16 bits although
135
they might be represented by 32 or 64 bits.<P>
136
The minimum integer ranges are deduced from the minimum integer sizes
137
as follows. Suppose b is the minimum number of bits that will be used
138
to represent a certain integral type, then:<P>
139
<UL>
140
<LI>For unsigned integer types the minimum range is [0, 2<SUP>b</SUP>-1];<P>
141
<LI>For signed integer types if <CODE>signed_range</CODE> is maximum
142
the minimum range is [-2<SUP>b-1</SUP>, 2<SUP>b-1</SUP>-1]. Otherwise,
143
if <EM>signed_range</EM> is symmetric the minimum range is [-(2<SUP>b-1</SUP>-1),
144
2<SUP>b-1</SUP>-1];<P>
145
<LI>For the type char which is not specified as signed or unsigned,
146
if <EM>char_type</EM> is signed then char is treated as signed, if
147
<EM>char_type</EM> is unsigned then char is treated as unsigned, and
148
if <EM>char_type</EM> is either, the minimum range of char is the
149
intersection of the minimum ranges of signed char and unsigned char.<P>
150
</UL>
151
<HR>
152
<P><I>Part of the <A HREF="../index.html">TenDRA Web</A>.<BR>Crown
153
Copyright &copy; 1998.</I></P>
154
</BODY>
155
</HTML>