lecture_slides_02_023-integersC
lecture_slides_02_023-integersC
of Washington
Integers
in
C
University
of
Washington
¢ Observa.ons
¢ C
Programming
§ |TMin
|
=
TMax
+
1
§ #include
<limits.h>
Asymmetric
range
§ § Declares
constants,
e.g.:
§ UMax
=
2
*
TMax
+
1
§ ULONG_MAX
§ LONG_MAX
§ LONG_MIN
§ Values
are
plaGorm
specific
§ See:
/usr/include/limits.h
on
Linux
Integers
in
C
University
of
Washington
Integers
in
C
University
of
Washington
Integers
in
C
University
of
Washington
Cas.ng
Surprises
¢ Expression
Evalua.on
§ If
you
mix
unsigned
and
signed
in
a
single
expression,
then
signed
values
implicitly
cast
to
unsigned
§ Including
comparison
operaXons
<,
>,
==,
<=,
>=
§ Examples
for
W
=
32:
TMIN
=
-‐2,147,483,648
TMAX
=
2,147,483,647
¢ Constant1
Constant2
Rela.on
Evalua.on
0 0
0U 0U
== unsigned
-‐1-1
0 0
< signed
-‐1-1
0U 0U
> unsigned
2147483647
2147483647
-‐2147483648
-2147483648
> signed
2147483647U
2147483647U
-‐2147483648
-2147483648
< unsigned
-‐1-1
-‐2
-2
> signed
(unsigned)-‐1
(unsigned) -1
-‐2
-2
> unsigned
2147483647
2147483647
2147483648U
2147483648U
< unsigned
2147483647
2147483647
(int)
(int)2147483648U
2147483648U > signed
Integers
in
C