2.67 Int Size is 32
★★
Problem:
You are given the task of writing a procedure int_size_is_32()
that yields 1 when run on a machine for which an int
is 32 bits, and yields 0 otherwise. You are not allowed to use the sizeof
operator. Here is a first attempt:
When compiled and run on a 32-bit SUN SPARC, however, this procedure returns 0. The following compiler message gives us an indication of the problem:
A. In what way does our code fail to comply with the C standard?
If the value of the right operand is negative or is greater than or equal to the width of the promoted left operand, the behavior it undefined.
B. Modify the code to run properly on any machine for which data type int
is at least 32 bits.
C. Modify the code to run properly on any machine for which data type int
is at least 16 bits.
Code:
Last updated