[Python-Dev] a small C style question

Fredrik Lundh fredrik@effbot.org
Fri, 2 Mar 2001 09:35:59 +0100


DEC's OpenVMS compiler are a bit pickier than most other compilers.
among other things, it correctly notices that the "code" variable in
this statement is an unsigned variable:

    UNICODEDATA:

        if (code < 0 || code >= 65536)
    ........^
    %CC-I-QUESTCOMPARE, In this statement, the unsigned 
    expression "code" is being compared with a relational
    operator to a constant whose value is not greater than
    zero.  This might not be what you intended.
    at line number 285 in file UNICODEDATA.C

the easiest solution would of course be to remove the "code < 0"
part, but code is a Py_UCS4 variable.  what if someone some day
changes Py_UCS4 to a 64-bit signed integer, for example?

what's the preferred style?

1) leave it as is, and let OpenVMS folks live with the
compiler complaint

2) get rid of "code < 0" and hope that nobody messes
up the Py_UCS4 declaration

3) cast "code" to a known unsigned type, e.g:

        if ((unsigned int) code >= 65536)

Cheers /F