<p>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 but not the initial assignments.</p>

<p>Is there anyway to make it catch these? I'm already at W4 but thought (hoped) there may be another setting somewhere.</p>

<p>Thanks,</p>

<pre><code>int foo(void)
{
    unsigned int fooUnsigned = 0xffffffff;
    int fooSigned = fooUnsigned; // no warning

    if (fooSigned &lt; fooUnsigned) // warning
    {
        return 0;
    }

    return fooSigned;
}
</code></pre>

<p>Update:</p>

<p>Quamrana is right, this is controlled by warning 4365 which appears to be off by default, even at W4. However you can explicitly enable it for a given warning level like so;</p>

<pre><code>#pragma warning (4 : 4365)
</code></pre>

<p>Which results in;</p>

<pre><code>warning C4365: 'initializing' : conversion from 'unsigned int' to 'int', signed/unsigned mismatch
</code></pre>

[{'answer_id': 75596, 'author': 'quamrana', 'author_id': 4834, 'author_profile': 'https://Stackoverflow.com/users/4834', 'pm_score': 4, 'selected': True, 'text': '<p>You need to enable warning 4365 to catch the assignment.</p>\n\n<p>That might be tricky - you need to enable ALL warnings - use /Wall which enables lots of warnings, so you may have some trouble seeing the warning occur, but it does.</p>\n'}, {'answer_id': 75711, 'author': 'Michael Burr', 'author_id': 12711, 'author_profile': 'https://Stackoverflow.com/users/12711', 'pm_score': 0, 'selected': False, 'text': "<p>@quamrana:</p>\n\n<p>There must be something beyond the /Wall option to enable warning 4365:</p>\n\n<pre><code>C:\\Temp&gt;cl /Wall /c foo.c\nMicrosoft (R) 32-bit C/C++ Optimizing Compiler Version 15.00.21022.08 for 80x86\nCopyright (C) Microsoft Corporation.  All rights reserved.\n\nfoo.c\nfoo.c(6) : warning C4018: '&lt;' : signed/unsigned mismatch\n</code></pre>\n\n<p>I see that Andrew got it to work, but does anyone have an idea why it's not working here?</p>\n\n<p>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).</p>\n"}, {'answer_id': 4883323, 'author': 'ottibus', 'author_id': 601104, 'author_profile': 'https://Stackoverflow.com/users/601104', 'pm_score': 2, 'selected': False, 'text': '<p>You can change the level of any specific warning by using /W[level][code]. So in this case /W34365 will make warning 4365 into a level 3 warning. If you do this a lot you might find it useful to put these options in a text file and use the @[file] option to simplify the command line.</p>\n'}]
['https://Stackoverflow.com/questions/75385', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1043/']