Page 1 of 1

Visual Studio Shoutout

Posted: Thu Aug 05, 2010 5:26 pm
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. :)

Re: Visual Studio Shoutout

Posted: Fri Aug 06, 2010 3:34 am
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.

Re: Visual Studio Shoutout

Posted: Fri Aug 06, 2010 11:42 am
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.

Re: Visual Studio Shoutout

Posted: Sat Aug 07, 2010 2:52 am
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 :)

Re: Visual Studio Shoutout

Posted: Tue Oct 05, 2010 10:49 am
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.