Make VS compiler catch signed/unsigned assignments?

后端 未结 3 623
臣服心动
臣服心动 2021-01-19 18:33

The Visual Studio compiler does not seem to warn on signed/unsigned assignments, only on comparisons. For example the code below will generate a warning on the if statement

3条回答
  •  佛祖请我去吃肉
    2021-01-19 19:03

    @quamrana:

    There must be something beyond the /Wall option to enable warning 4365:

    C:\Temp>cl /Wall /c foo.c
    Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 15.00.21022.08 for 80x86
    Copyright (C) Microsoft Corporation.  All rights reserved.
    
    foo.c
    foo.c(6) : warning C4018: '<' : signed/unsigned mismatch
    

    I see that Andrew got it to work, but does anyone have an idea why it's not working here?

    The Visual Studio docs indicate that it should, but I can't even get the example program in the docs to give the C4365 warning (though it does give the related C4245 warning - but that occurs with just a /W4 option anyway).

提交回复
热议问题