Thread: Disable specific warning?

  1. #1
    Registered User
    Join Date
    Oct 2007
    Posts
    166

    Disable specific warning?

    I'm using Visual studio 2008 SP1 and I need to find a way to disable a specific warning while compiling at a high warning level. Is there something I can use to disable a warning for the whole project?

    I know I can use this to disable/reenable it locally in the code:

    #pragma warning( disable : 4100)
    ...do stuff
    #pragma warning(default : 4100)

    ...but I would like something that is project wide.

  2. #2
    Registered User
    Join Date
    Oct 2007
    Posts
    166
    Nevermind, I found that I can add:

    /wd4100

    in the command line for C/C++ settings to disable warning C4100 as an example.

  3. #3
    Registered User
    Join Date
    Oct 2007
    Posts
    166
    ...but I have another question. When I'm doing the below to free the memory of a std::vector<int>:

    Code:
    theVector.clear();
    theVector.swap(std::vector<int>());
    ...I'm getting this warning at warning level 4:

    Code:
    warning C4239: nonstandard extension used : 'argument' : conversion from 'std::vector<_Ty>' to 'std::vector<_Ty> &'
    1>        with
    1>        [
    1>            _Ty=int
    1>        ]
    1>        A non-const reference may only be bound to an lvalue
    The code is working to free the vector but if possible I'd like to get rid of the warning. What to do?

  4. #4
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    5,108
    You just need to reverse a bit...

    Soma

    Code:
    std::vector<int>().swap(theVector);

  5. #5
    Registered User
    Join Date
    Oct 2007
    Posts
    166
    Quote Originally Posted by phantomotap View Post
    You just need to reverse a bit...

    Soma

    Code:
    std::vector<int>().swap(theVector);
    Ok that seems to do the trick, thanks!

    If I can get a second opinion that would be great though. I need to be sure this is a safe way to do it.

  6. #6
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    5,108
    Safe?

    *shrug*

    "Safe" doesn't enter into it. It is legal to call a method of a temporary. (That's why the "std:fstream flush trick" works.) How you have been doing it is illegal.

    Soma

  7. #7
    Registered User
    Join Date
    Oct 2007
    Posts
    166
    Quote Originally Posted by phantomotap View Post
    Safe?

    *shrug*

    "Safe" doesn't enter into it. It is legal to call a method of a temporary. (That's why the "std:fstream flush trick" works.) How you have been doing it is illegal.

    Soma
    Alright no offense, this will affect a lot of code if I do implement it so I just want to make sure it is a valid way and not just one persons leet haxx. Thanks for the extra info.

    Edit: I have read some other threads on the internet now and they point to the same thing as your example so it seems to be the way to go. Thanks.
    Last edited by DrSnuggles; 05-07-2009 at 09:29 PM.

  8. #8
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    5,108
    O_o

    I wasn't offended. I was only offering context by which to interpret the statements.

    This is basically the same as "(some_std__string + "some c string").c_str()" which you'll find everywhere.

    Soma

  9. #9
    Registered User
    Join Date
    Oct 2007
    Posts
    166
    Ok, I thought you might have been offended because I wanted a second opinion and didn't trust your coding skills. Luckily it was not so. Thanks again.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 10
    Last Post: 07-10-2008, 03:45 PM
  2. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  3. <Gulp>
    By kryptkat in forum Windows Programming
    Replies: 7
    Last Post: 01-14-2006, 01:03 PM
  4. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  5. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM