By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,331 Members | 1,428 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,331 IT Pros & Developers. It's quick & easy.

#pragma warning (disable:4214)

P: 1
hi folks,

I want to know about this #pragma warning (disable:4214) ..
what exactly such kind of things does.and tell some more about
#pragma how exactly it is useful.

regards,
Maruthi
Dec 13 '05 #1
Share this Question
Share on Google+
1 Reply


P: 8
hi folks,

I want to know about this #pragma warning (disable:4214) ..
what exactly such kind of things does.and tell some more about
#pragma how exactly it is useful.

regards,
Maruthi
I see I'm reading your post about 9 months after you posted it, so you probably already have your answer. But just in case you don't...

From what I understand, #pragma directives in general are pre-compiler directives that are specific to a development environment. They provide options in telling the compiler how to compile your code. With your specific example, you are telling the compiler to not generate warnings for warning message 4214.

Let me give you an example. In a C# program I am writing, I declared a structure:

Expand|Select|Wrap|Line Numbers
  1. public struct MyStruct
  2. {
  3. public string Field1, Field2;
  4. }
  5.  
When I build the app, the compiler kept giving me warning message 0649 (the fields are never assigned to and will have always have the default value of null). Well in my app it is perfectly acceptable to have a null. So to shut these warnings off, I enclosed the struct in a #pragma directive:

Expand|Select|Wrap|Line Numbers
  1. #pragma warning disable 0649
  2.  
  3. public struct MyStruct
  4. {
  5. public string Field1, Field2;
  6. }
  7.  
  8. #pragma warning restore 0649
  9.  
The most important thing there is the last line. In other areas of the app I may want to know about unassigned variables. So shutting off that warning for the entire compilation process would be bad. By encapsulating just that one struct in a disable/restore block, the compiler ignores the warning just while building the struct information.

There are lots of other nifty things you can do with #pragma directives. Dig around on msdn.microsoft.com. There's lots of information there.
Sep 4 '06 #2

Post your reply

Sign in to post your reply or Sign up for a free account.