open-watcom / open-watcom-v2

Open Watcom V2.0 - Source code repository, Wiki, Latest Binary build, Archived builds including all installers for download.
Other
970 stars 159 forks source link

strange warning "comparison result always 1" #1240

Closed Baron-von-Riedesel closed 7 months ago

Baron-von-Riedesel commented 7 months ago

this simple test code always gives warning "comparison result always 1" ( version 02/2024 ):

#include <stdio.h>

void VDMA_Write( unsigned short port )
{
    if(( port >= 0x00 && port <= 0x07 ) || ( port >= 0xC0 && port <= 0xCE )) {   // <---- warning about this line
       printf("gotcha! port=%X\n", port);
    }
}
int main( int argc, char * *argv )
{
    VDMA_Write( 0 );
    VDMA_Write( 0x20 );
    return 0;
}

cmd used to compile

\ow20\binnt\wcc386 -q -I\ow20\h vdma.c

The generated code is correct, though.

jmalak commented 7 months ago

Thanks for your problem report. I checked compiler processing and it is reported for first condition port >= 0 which is always true.

    if(( port >= 0x00 && port <= 0x07 ) || ( port >= 0xC0 && port <= 0xCE )) {   // <---- warning about this line

The same is reported by OW 1.9 compiler. It looks like surprising message but it is correct.

Baron-von-Riedesel commented 7 months ago

Ah yes, I see. with a typecast to a signed short before 'port' I got rid of the warning. Thanks!