Next Previous Contents

16. Decimal constants greater than 0x7FFF are actually long ints

The language rules for constant numeric values specify that decimal constants without a type suffix that are not in integer range must be of type long int or unsigned long int. This means that a simple constant like 40000 is of type long int, and may cause an expression to be evaluated with 32 bits.

An example is:

        unsigned val;
        ...
        if (val < 65535) {
            ...
        }

Here, the compare is evaluated using 32 bit precision. This makes the code larger and a lot slower.

Using

        unsigned val;
        ...
        if (val < 0xFFFF) {
            ...
        }

or

        unsigned val;
        ...
        if (val < 65535U) {
            ...
        }

instead will give shorter and faster code.


Next Previous Contents