Annoying warning



  • On 22/02/2016 at 06:57, xxxxxxxx wrote:

    User Information:
    Cinema 4D Version:   R17 
    Platform:   Windows  ;   
    Language(s) :     C++  ;

    ---------
    Hello.

    The following code gives me a very annoying warning:
    warning C4800: 'Bool' : forcing value to bool 'true' or 'false' (performance warning)

    	
    String name = "AnyName";
    std::map<String, Real *> map;
    bool name_exists = map.find(name) != map.end();
    

    Is there any way to get rid of it ?

    Thank you.



  • On 22/02/2016 at 06:59, xxxxxxxx wrote:

    Have you tried casting the result:

    bool name_exists = static_cast<bool>(map.find(name) != map.end());



  • On 22/02/2016 at 08:51, xxxxxxxx wrote:

    Try using 'Bool' instead (uppercase B). If I remember correctly, the C4D
    Bool datatype is the same as Int32, thus you get the warning from
    converting an integer value to a native C++ bool.



  • On 23/02/2016 at 00:31, xxxxxxxx wrote:

    I have tried both of these.
    Still getting it.



  • On 23/02/2016 at 02:43, xxxxxxxx wrote:

    Yeah, nevermind my comment. I misread and thought you were using a maxon::HashMap, not std::map.
    The latter will certainly not return "Bool" from any function. :) Not sure where the error comes from then.



  • On 23/02/2016 at 07:41, xxxxxxxx wrote:

    This is a bit more explicit but may remove the performance warning:

    bool name_exists = (map.find(name) != map.end())?true:false;
    


  • On 23/02/2016 at 08:05, xxxxxxxx wrote:

    Or just disable the warning in the compiler settings.



  • On 23/02/2016 at 09:16, xxxxxxxx wrote:

    Hi,

    I certainly wouldn't suggest to disable any compiler warning. After all that's begging for bugs...
    After looking at your three lines of code posted in the beginning, I don't think, the warning belongs to these lines. As Niklas already pointed out, you are not using any Bool in there. Actually I'm wondering, why you aren't using the C4D datatypes? There is a HashMap in the SDK as well. At least I'd try not to mix those types and have a clear line between C4D datatypes and any other datatypes, when using external libs. So you can keep casting to a minimum and don't need to think about datatype conversion all over the place.



  • On 23/02/2016 at 09:36, xxxxxxxx wrote:

    Originally posted by xxxxxxxx

    I certainly wouldn't suggest to disable any compiler warning. After all that's begging for bugs...

    Oh I certainly would with MSVC. 😂 I think my favourite useless warning is C4127.
    And by the way, the Cinema 4D API and SDK Project has quite a bunch of MSVC warnings disabled
    by default as well.



  • On 25/02/2016 at 03:34, xxxxxxxx wrote:

    It could be the std::map with the String as key value because the C4D String class may not correctly support the comparison function object used by the map. Do you still get the same if you use a std::string instead?

    The != check will return a compatible bool, so this cannot be it.



  • On 25/02/2016 at 04:45, xxxxxxxx wrote:

    Thank you for your answers.
    To reproduce the warning, copy paste these 3 lines in any project.
    I will use C4D data structures.


Log in to reply