Visual Studio Shoutout

All off topic discussions go here. Everything from the funny thing your cat did to your favorite tv shows. Non-programming computer questions are ok too.
Post Reply
User avatar
blobmiester
Member
Member
Posts: 45
Joined: Fri Jul 16, 2010 9:49 am

Visual Studio Shoutout

Post by blobmiester »

I just installed my shiny new copy of visual studio 2010 and I noticed a new feature. At least I think it's new. Anyway, it's called Code Analysis. I turned it on and did a build of my code and it found the following error in my gdt::initialize function.
warning C6334: sizeof operator applied to an expression with an operator might yield unexpected results

Code: Select all

void gdt::initialize()
{
	// Initialize Pointer
	sm_pointer.limit = (sizeof(DESCRIPTOR) * GDT_MAX_DESCRIPTORS) - 1;
	sm_pointer.base = (uint32_t)(sm_table);
	
	// Initialize Table
	memset(sm_table, 0, sizeof((sizeof(DESCRIPTOR) * GDT_MAX_DESCRIPTORS)));
}
I looked up what Code Analysis is supposed to do, and it apparently checks code against a super strict set of rules and guidelines and emits tons of warnings to help find crazy typos (like the above). Awesome! (Now I've got a list of little things to fix on my warnings list :P)

I don't know how I ever would of found that typo. I probably wouldn't have come back and looked over my GDT code for awhile yet. :) Needless to say, Code Analysis is now on for all my projects. I haven't been this impressed with an IDE since I first started using one. :)
User avatar
Creature
Member
Member
Posts: 548
Joined: Sat Dec 27, 2008 2:34 pm
Location: Belgium

Re: Visual Studio Shoutout

Post by Creature »

CodeLite offers a similar feature called 'CppCheck' which checks for unused functions, variables and arrays that are allocated but seemingly never freed (memory leaks with e.g. operator new), suggests class functions to be 'const' whenever appropriate, etc. Every now and then it's useful to run it but it just checks some basic things, nothing too special.
When the chance of succeeding is 99%, there is still a 50% chance of that success happening.
User avatar
blobmiester
Member
Member
Posts: 45
Joined: Fri Jul 16, 2010 9:49 am

Re: Visual Studio Shoutout

Post by blobmiester »

This is all that visual studio checks for:

http://msdn.microsoft.com/en-us/library/a5b9aa09.aspx

Some of it is windows specific but there is a lot there is handy for just C++ development.

I've been using now and I cleaned up all the warnings it gave me. There weren't any false positives so thats pretty nifty. :)

It 'knows' how the standard C/C++ library should and shouldn't be used (at least the Visual C++ library). And there is a file somewhere that you can add your function definitions so it'll know how your function is supposed to be used to.
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Re: Visual Studio Shoutout

Post by Candy »

blobmiester wrote:I've been using now and I cleaned up all the warnings it gave me. There weren't any false positives so thats pretty nifty.
Compared to what Microsoft used to produce (C4996, C4512... and those are just off the top of my head) that's a good thing. Sounds like I might actually start to like that feature :)
Gaidheal
Member
Member
Posts: 51
Joined: Mon Oct 04, 2010 6:23 pm

Re: Visual Studio Shoutout

Post by Gaidheal »

Not a huge fan of VS (I was when I was younger, then I found GCC and Eclipse) but that's actually quite a nicely implemented feature, for once. I do have VS2010 myself, mostly so that can I test oddly performing against different compilers or copy and paste someone else's VS project and have it 'just work', so I might play later.
Post Reply