Thread: Change what you get warnings for in Visual studio

  1. #1
    Registered User
    Join Date
    Oct 2006
    Location
    UK/Norway
    Posts
    485

    Change what you get warnings for in Visual studio

    I am starting to get tired of some of the warnings I get when I compile. Is there a way to make the compiler not print out so many warnings?

    I dont want warnings when converting from float to int or when I compare an unsigned int to a signed int.

    Or am I doing something wrong and should fix my code so I dont get the warnings at all?

  2. #2
    Registered User
    Join Date
    May 2006
    Posts
    903
    Well generally you actually want to take note of those warnings. They could actually help you out with a logic error some day.

  3. #3
    Registered User
    Join Date
    Oct 2006
    Location
    UK/Norway
    Posts
    485
    I dont want to remove all warnings, just the once who are stupid(or I think is stupid)

    Like I get a warning for this:
    for(int i = 0; i < someSTDvector.size(); i++)

    Saying that I compare a signed and a unsigned int. I cant see why that would be a problem?

  4. #4
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    It is a problem and will bite you someday if you don't heed it. Make both types the same type. In this case, you can make i unsigned. Size can never be negative anyway.
    Take heed to these warnings and know how to fix them instead of suppressing them.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  5. #5
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    You should cast a float if you convert it to int. That way, the compiler will accept it happily.

    You should not compare unsigned types with signed types, as that can lead to "interesting problems" if the unsigned value is in the "negative" range of the signed number. E.g. a short of 40000, is that bigger or smaller than 32767?

    Warnings are there, mainly, because the compiler programmer thinks it's something that is likely to cause a problem.

    For example, a float can be much bigger than an int (approx 1E10 vs 1E37), so it's valid for the compiler to warn about it. And as I mentioned above, mixing signed and unsigned values is also causing "range problems".

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  6. #6
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Like I get a warning for this:
    for(int i = 0; i < someSTDvector.size(); i++)
    It should be:
    Code:
    for (std::vector<T>::size_type i = 0; i < someSTDvector.size(); ++i)
    where T is the value type for someSTDvector. Making i an unsigned int as Elysia suggested should also work, but pedantically speaking is not correct.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  7. #7
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Oh yes, of course, it's not always a good thing to mix types (especially not without a cast). If something returns a DWORD, then use a variable of DWORD to store that and not uint32_t or something else.
    And, as laserlight mentions, use std::vector<T>::size_type for the vector since that's what it returns. It guarantees that there will be no problem with the type, wherever the code will compile.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  8. #8
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by laserlight View Post
    It should be:
    Code:
    for (std::vector<T>::size_type i = 0; i < someSTDvector.size(); ++i)
    where T is the value type for someSTDvector. Making i an unsigned int as Elysia suggested should also work, but pedantically speaking is not correct.
    And if you use it often, you could do:
    Code:
    typedef std::vector<T>::size_type STDsize;
    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  9. #9
    Registered User
    Join Date
    Oct 2006
    Location
    UK/Norway
    Posts
    485
    Point taken. I will change my code, not Visual Studio

  10. #10
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Good student
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. sorting the matrix question..
    By transgalactic2 in forum C Programming
    Replies: 47
    Last Post: 12-22-2008, 03:17 PM
  2. Problem Compiling Program
    By wco5002 in forum C++ Programming
    Replies: 13
    Last Post: 11-06-2007, 12:56 PM
  3. header file bringing errors?
    By bluehead in forum Windows Programming
    Replies: 4
    Last Post: 08-19-2003, 12:51 PM
  4. ........ed off at functions
    By Klinerr1 in forum C++ Programming
    Replies: 8
    Last Post: 07-29-2002, 09:37 PM
  5. wont write to variable
    By Klinerr1 in forum C++ Programming
    Replies: 3
    Last Post: 07-25-2002, 10:00 PM