Thoughts on FxCop (.NET)

FxCop is very useful tool for code review. I was doing a study on it, And some crazy thoughts raised on my mind... what will happen if FxCop is run on FxCop.exe...? FxCop came clean. No Active errors! But there were 135 errors but under "Excluded in source" section.

Then another crazy thought raised in my mind... what will happen if FxCop is run on .NET core dlls...Here FxCop came Nasty! There were thousands of Active errors! Why didn't Microsoft comply with FxCop?A fourm reply said "FxCop was designed and generated long after the original framework design was in place
"http://social.msdn.microsoft.com/Forums/en-US/netfxbcl/thread/5abda75d-1177-4a91-9b20-dd17c42d4567 Tidbit: How to mark a bug as “Excluded in source”? Code that causes the error should be marked with this C# attribute “CodeAnalysis.SuppressMessageAttribute” Example: [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1804:RemoveUnusedLocals")] private void test() { string name; //unused variable // some code here } Please note that above exclusion will only work if “CODE_ANALYSIS” compiler directive is added to project properties.

Common crashes & compile errors (C++)

This topic I will cover some common compile errors encountered in C++...
1. Error C2243: 'type cast' : conversion from 'DerivedClassXXX *' to 'BaseClassXXX *' exists, but is inaccessible.
Resolution: Most common cause is when deriving from your base class acces specifier keyword "public" might be missing
//Here is the code change in Bold
class DerivedClass : public BaseClass
{
///your code goes here
}
The C# touch: The "public" keyword used here to fix this issue is not applicable in C# environment. And also inheritance is always public by default there.
2. Program crashes on reading params from main()
Make sure correct overload is called. Below is one correct overload.
int main( int argc, char *argv[])
{
}
First param supplies number of arguments, make sure to check this one first.
Note: argv[0] will contain program's name with it's path.
For more clarity check this link below:
3. fatal error C1010: "unexpected end of file while looking for precompiled header directive" when compiling your win32 dll or exe
It can be as simple as not including stdafx.h file in to your cpp class implementation files. Other reasons visit :-) http://support.microsoft.com/kb/815644

Include Guard in C++

Include guards prevent multiple includes of the same file in C++, MFC.

They are preprocessor directives. Pre-processor directives will be also called as compiler directives. These are instructions that will not be part of the executable/object file instead commands to the compiler when it generates the executable!

When you require include guards?

When you get “redefinition; different storage class” errors in your visual studio it means that same header file is included twice somewhere directly or indirectly. This will be difficult to find in complex code. So easy option is to provide include guard for your most used header files. Syntax given below…

#ifndef YOURFILENAME_H

#DEFINE YOURFILENAME_H

//YOUR HEADER FILE CODE GOES HERE

#endif