Skip to main content
GameDev.net gamedev.net
🔒 Locked

Managing warnings in MS VC++

Started by Kylotan Oct 17, 2008 at 6:16 AM 8 replies 3.6k views
Original Post
Kylotan
Kylotan
With gcc, I can turn off and on specific types of warning quite easily at the command line, and they're generally well documented all in one place. With Visual C++, there is apparently even more fine-grained control over warnings, but they're all given obscure numbers and their own separate page in the MSDN documentation. This means that if I want to enable a certain type of warning, trying to find out which warning number to feed to the #pragma is virtually impossible. Is there a better way of being able to find a warning number or numbers in Visual C++ for a given situation? For example, I want it to warn on converting floats to ints and the like. However changing the overall warning level is not an option.
jochen
jochen
What about
- enable all warning.
- run a simple program, that produces your warning (assigns a float value to an int var).
- look up the warning number in the output.

alternative google for "msdn warning conversion float to int", and find: C4244

Well, admitted not really convenient, but not "virtually impossible any more".

Best Jochen
Why did Doug Gregor create the empty directory?
the_edd
the_edd
Quote:
Original post by Kylotan
With Visual C++, there is apparently even more fine-grained control over warnings, but they're all given obscure numbers and their own separate page in the MSDN documentation. This means that if I want to enable a certain type of warning, trying to find out which warning number to feed to the #pragma is virtually impossible.


It's actually pretty easy. When you see the warning on the command line, you note it's number.

Quote:
For example, I want it to warn on converting floats to ints and the like. However changing the overall warning level is not an option.


It would be better to turn warning levels up very high to start with and selectively disable warnings that you really can't get rid of, rather than starting with a weak warning level and selectively enabling specific warnings you assume will exist.
Kylotan
Kylotan
Quote:
Original post by the_edd
Quote:
Original post by Kylotan
With Visual C++, there is apparently even more fine-grained control over warnings, but they're all given obscure numbers and their own separate page in the MSDN documentation. This means that if I want to enable a certain type of warning, trying to find out which warning number to feed to the #pragma is virtually impossible.

It's actually pretty easy. When you see the warning on the command line, you note it's number.

*sigh* That's not practical if there currently is no warning. Or if I don't even know if such a warning may exist. That's the whole point.

Quote:
Quote:
For example, I want it to warn on converting floats to ints and the like. However changing the overall warning level is not an option.


It would be better to turn warning levels up very high to start with and selectively disable warnings that you really can't get rid of, rather than starting with a weak warning level and selectively enabling specific warnings you assume will exist.

Individual developers don't always have the luxury of being able to control the build settings for things they work on. I am in such position. However, if I can submit a request to change the settings to include a few extra warnings, I can do that - if I can find out what the magical invocations for those warnings are in the first place.

Besides, at the highest warning level there are plenty of things which emit warnings that aren't bugs, and it would take a long time to trawl through those on a big project. The various 'levels' are pretty arbitrary as it is. Being able to look them up by number isn't an excuse for poor documentation. I should be able to see what sort of warnings are available, and that I might want certain warnings to be turned on before I ever hit them - that just seems like a sensible thing to want from a compiler.

[Edited by - Kylotan on October 22, 2008 8:47:05 AM]
SiCrane
SiCrane
Quote:
Original post by Kylotan
I should be able to see what sort of warnings are available, and that I might want certain warnings to be turned on before I ever hit them - that just seems like a sensible thing to want from a compiler.

Fire up MSDN, do a search for C1001 and synchronize the table of contents with the current page if using an offline version of MSDN. On the left hand side of the screen should be a list of every warning/error available to the compiler. From there you can click on each entry and see what the warning/error corresponding to the numeric code value is. Of course, you don't need to do this for every warning. If you're warning level is set to /W3 then you only need to look through the 4000s.
Kylotan
Kylotan
Quote:
Original post by SiCrane
If you're warning level is set to /W3 then you only need to look through the 4000s.

I'm not sure what you mean by that - all the warnings seem to be numbered between 4000 and 4999, and each of the subsections contains warnings from all 4 warning levels. The numbers don't seem to correspond to the levels.

stonemetal
stonemetal
try #pragma warning(push, 4 )
to turn on wall(well warning level 4 anyway) and #pragma warning(pop) at the end of the file.
To turn on specific warnings use
#pragma warning(warning_level:warning_number)
and give it the warning level you are running at.

Here is the list of warnings that are off by default
http://msdn.microsoft.com/en-us/library/23k5d385.aspx
Kylotan
Kylotan
There is no "the file". I am not trying to fix a certain line of code or a file. I'm trying to do what would be trivial in GCC, and say, "hmm, I'd like the compiler to warn me when I do something like , how can I do that?" The list of warnings off by default is no help here. They are spread across the various warning levels.
stonemetal
stonemetal
Quote:
Original post by Kylotan
There is no "the file". I am not trying to fix a certain line of code or a file.
Then replace a file with all files.
Quote:
I'm trying to do what would be trivial in GCC, and say, "hmm, I'd like the compiler to warn me when I do something like , how can I do that?"
Yes and you were given the answer change your compiler switches much like using wall on gcc you can use wall on vc++. You don't want to touch command line parameters so a per file method was suggested.
Quote:
The list of warnings off by default is no help here. They are spread across the various warning levels.
If you want to turn on any of the warnings that are not currently on adding #pragma (level at which you wish the warning to turn on at: warning number or list of warning numbers) so if you are forced to build at /W3 then you can turn 4100(a /W4 warning) on by adding #pragma(3:4100). The list was mentioned so that you could more easily find the warnings you were looking for.

Also if the project has to be built at /W3 that doesn't mean you can't change the build for individual files just right click on them and go to properties. If you want better help than that you are going to have to ask a better question.
Kylotan
Kylotan
Quote:
Original post by stonemetal
Quote:
Original post by Kylotan
There is no "the file". I am not trying to fix a certain line of code or a file.

Then replace a file with all files.

That's not even remotely practical. There are thousands.

Quote:
Quote:
I'm trying to do what would be trivial in GCC, and say, "hmm, I'd like the compiler to warn me when I do something like , how can I do that?"
Yes and you were given the answer change your compiler switches much like using wall on gcc you can use wall on vc++.

The whole point is that you don't need to use -Wall on gcc to find these things. You can look at http://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html and get a decent appreciation at a glance of the options available to you.

Quote:
You don't want to touch command line parameters so a per file method was suggested.

Where did I say I don't want to touch command line parameters? What I did say is that I can't just copy the warning numbers I want from the command line because they don't exist. I do not and cannot know the numbers without either triggering them or finding them in the docs. The same applies for gcc, but at least with gcc the docs are 100x more convenient.

Quote:
If you want better help than that you are going to have to ask a better question.

The original question was fine. It was "[Warnings are] all given obscure numbers and their own separate page in the MSDN documentation. [...] Is there a better way of being able to find a warning number or numbers in Visual C++ for a given situation?" I wasn't asking how to use #pragma, which I've managed to do just fine for 10 years now, or on how a project's build settings should ideally be set up, which isn't always under someone's control.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.