- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Here are two cases when a Warning #186 is displayed:
// Case 1:
...
for( RTuint t = 0; t < ( ( RTuint )NUMBER_OF_TESTS - 1 ); t++ )
{
...
}
...
../
Note 1: 'RTuint t = 0' is not a comparison with 0. It is assignment of 0 to the variable 't'.
// Case 2:
...
if( pIoParams->uiEOLBytes >= 0 && pIoParams->uiEOLBytes <= 2 )
{
...
}
else
break;
...
../
Note 2: The 'if' statement verifies that 'pIoParams->uiEOLBytes' is in a range from 0 to 2 and
valid values are as follows: 0, 1, or 2.
A processing is not allowed if the value of 'pIoParams->uiEOLBytes' is outside of the range.
A word 'pointless' seems to me too "harsh" because I really know what I need to verify and a more neutral message
will look significantly better, like:
Warning #186: possibly unnecessary comparison of unsigned integer with zero
and please consider this.
My Development Environment:
OS: Windows XP 32-bit
IDE: Visual Studio 2005 SP1
Compilers: Intel C++ / Microsoft C++ / Borland C++ / MinGW / Turbo C++
Intel C++ compiler version ( Composer XE 2011 Update 9 ):
Intel C++ Compiler XE 12.1.3.300 [IA-32]
Intel C++ compiler command line options:
/c /Od /D "WIN32" /D "_CONSOLE" /D "_DEBUG" /D "_VC80_UPGRADE=0x0710"
/D "_UNICODE" /D "UNICODE" /GF /EHsc /RTC1 /MTd /GS /fp:precise /W5 /nologo /ZI /TP
/Qopenmp /Qdiag-disable:111,673
Best regards,
Sergey
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
In case 1 why do you think the compiler is complaining about theassignment and not the conditional?
In case 2:
if( pIoParams->uiEOLBytes >= 0 && pIoParams->uiEOLBytes <= 2 )
What is the point of the first conditional? if uiEOLBytes is unsigned then it is always going to be
greater than or equal to 0.
Why didn't you just write the if statementlike:
if( pIoParams->uiEOLBytes <= 2 )
Judy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
In case 1 why do you think the compiler is complaining about theassignment and not the conditional?
...
for( RTuint t = 0; t < ( ( RTuint )NUMBER_OF_TESTS - 1 ); t++ )
^
../
[SergeyK] When a message is displayed there is a circumflex sign pointing to 't = 0' part of the 'for' statement.
In case 2:
if( pIoParams->uiEOLBytes >= 0 && pIoParams->uiEOLBytes <= 2 )
What is the point of the first conditional? if uiEOLBytes is unsigned then it is always going to be
greater than or equal to 0.
Why didn't you just write the if statementlike:
if( pIoParams->uiEOLBytes <= 2 )
[SergeyK] I agree, but this is implicit form.Due tostrict coding standards on the projectexplicit forms must
be always used.
I simply would like to repeat that a more neutral message will look better:
Warning #186: possibly unnecessary comparison of unsigned integer with zero
Best regards,
Sergey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Sergey,
Are you sure you're seeing the carat appearing in the right place? Here's my code which I based on yours:
And my output:
[bash]Q:u105822>icl /Wall /c test2.cpp Intel C++ Intel 64 Compiler XE for applications running on Intel 64, Ve rsion 12.1.4.325 Build 20120410 Copyright (C) 1985-2012 Intel Corporation. All rights reserved. test2.cpp test2.cpp(8): warning #186: pointless comparison of unsigned integer with zero for(unsigned int t = 0; t < ((unsigned int) NUMBER_OF_TESTS-1); t++) ^
[/bash]For some reason the code syntax is changing the less than symbol to html lt, but the carat for me is pointing to the comparison.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Yes I see the same thing as Brandon as far as where the carot is pointing.
And I don't think the "sometimes" is accurate -- it's always unnecessary to compare an unsigned number to 0. So I don't really seea problem with the text of the diagnostic.
Judy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- #include
- constintNUMBER_OF_TESTS=1;
- voidgoo(unsignedintn);
- voidfoo(){
- for(unsignedintt=0;t<((unsignedint)NUMBER_OF_TESTS-1);t++)
- goo(t);
- }
No. Could youdo a very quick verification with:
...
const int NUMBER_OF_TESTS = 1024;
...
and please set a 'Tahoma' font (size 8 ) for a Visual Studio's Output Window.
Best regards,
Sergey
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page