views:

425

answers:

2

I can inhibit many warnings in Visual Studio 2005 SP1 in the C/C++ Advanced property page, which causes the IDE to use the /wd switch on the command line which invokes the compiler. However, when I try to inhibit warning 4200 (nonstandard extension used : zero-sized array in struct/union), it still appears when I compile. (Of course it's justified; I'm just not in a position to fix the code, nor would it be worth bothering, because it's generated, and the warning is entirely benign under the circumstances.) Does anybody happen to know if this is a bug in the compiler? Or might there be something I can do about it?

+2  A: 

To completely disable the warning in the file you can add the following to the top of the file

#pragma warning(disable:2400)

If you want some more flexibility other than a blanket disable for the file, the following page lists several other more fine grained options.

It's unclear based on your information as to whether or not it's a bug in the compiler or a configuration issue. I would lean towards a configuration issue, specifically conflicting compiler options that is making it difficult to suppress the warning.

EDIT

OP mentioned they can't control the generated code so they can't directly include the pragma. If that's the case then try this trick. Say the file name is Generated.cpp. No longer include Generated.cpp as one of the files to compile. Instead create a new file called Example.cpp with the following contents

#pragma warning(disable:2400)
#include "Generated.cpp"

Now you'll get the text of Generated.cpp with the disabled warning by only compiling Example.cpp.

JaredPar
You're fast! :)
JP Alioto
This is generated code and the generator won't do that for me. It's possible I might be able to use some kind of prefix header, specified on the command line, instead, so I'll look into that.
Integer Poet
Wrapping up generated code to get rid of warning is a hack and a horrible idea. Especially in the Windows world where scripting is an after thought and make files are a horrible microsoft abortion.
ojblass
@ojblass, really? The OP said he is completely unable to change the code. This is an acceptable method of getting rid of a warning in code that cannot possible be changed. You can say "change the code all you want" but if the OP cannot change the code then what do you suggest I say. "Change it anyways?"
JaredPar
@Jared no it is masking over the problem and making a maintenance nightmare. Suppose he introduces another warning... someone has to go find his wrapping of this function and fix it. I have worked with enough gnerated to know better.
ojblass
@ojblass, i really don't understand your comment in the face of your answer (i did not down vote it). You're criticism of my answer is that it's hiding the problem, yet you post an answer telling the user how to hide the problem?
JaredPar
I did not think you downvoted anything. Using the original file and supressing the warning using the correct compiler option is far better than wrapping up the file into another filename. It adds another level of indirection. The OP was asking how to supress the warning not create a hack to hide it.
ojblass
I think you both agree suppressing the warning is appropriate. Exactly how that is achieved is an implementation detail. The phrase "horrible idea" was probably a poor choice because it raised the tension in the room without benefit.
Integer Poet
A: 

You mean like with pragma?

#pragma warning( disable : 2400 )
JP Alioto
This is generated code and the generator won't do that for me.It's possible I might be able to use some kind of prefix header, specified on the command line, instead, so I'll look into that.
Integer Poet
In the IDE, this is available as a C/C++ Advanced property called "Force Includes", and on the command line it's called /FI. It works. I stuck this line such a header and it succesfully inhibited the warning.#pragma warning(disable:4200)So the pragma works where the command line switch does not. This approach also has the advantage of allowing comments.
Integer Poet
In the IDE, this is available as a C/C++ Advanced property called "Force Includes", and on the command line it's called /FI. It works. I stuck this line into such a header and it succesfully inhibited the warning. #pragma warning(disable:4200)So the pragma works where the command line switch does not. This approach also has the advantage of allowing comments.
Integer Poet
And it seems I cannot delete my own duplicate comment, above, even though it is mine, because I do not have voting privileges. I smell a category error.
Integer Poet