Aug 052008
 

I can’t just bear the intellisense of VS2005. So went out to find ways to disable this feature since I have another intellisense (you know right?) 😉 package from a private vendor.

Here are some ways to disable this feature in VS2005…

  1. Rename \Program Files\Microsoft Visual Studio 8\VC\vcpackages\feacp.dll
    I’ve renamed it to “feacp.dll.renamed_to_disable_intellisense”. Hehe
  2. Open .ncb file of your project exclusively and then open your solution. You will get a warning which you will enjoy seeing. Take a look

Helped me a lot. Hope Microsoft(r) fixes this crap soon!! 😐 Sometimes I do wonder, didn’t they test this at all ? 🙁

Most probably you can do the same in VS2008. But not everybody is as lucky as I am. I have another intellisense software but don’t know whether others have the same option.

[Update]
http://blogs.msdn.com/vcblog/archive/2007/11/19/controlling-intellisense-through-macros.aspx
[/Update]

Aug 042008
 

Well what is deprecation? It’s just a way to tell the user that a better/safer function is available for a function which he is using!

For e.g. strcpy.

If you use strcpy in VC8 we’ll get a warning saying that it’s deprecated, instead use strcpy_s which is the secure version of this API.

So the question is how to deprecate a function using VC++ compiler. There are two options in VC++…

  1. Using __declspec(deprecated)
  2. Using #pragma deprecated

Using __declspec(deprecated) compiler directive.

// Helper #defines for deprecation compiler directive
#define deprecate __declspec(deprecated)
#define deprecate_msg(message) __declspec(deprecated(message))

First version is just plain, just produces default compiler warnings, while second version prints out a custom message along with the normal deprecation message.

// Deprecate a function
void deprecate OldFunction() {}

// Deprecate a class/struct
class deprecate OldClass {};

// This time with custom message //

// Deprecate a function, also tell the user that a better option exists
void
deprecate_msg( "******OldFunction is deprecated, start using NewFunction******" )
OldFunction()
{}
// Deprecate a class/struct, also tell the user that a better option exists
class
deprecate_msg( "******OldClass is deprecated, start using NewClass******" )
OldClass
{};

The output that I get looks like this

\consolegunieapig\consolegunieapig.cpp(144) : warning C4996: ‘OldFunction’ was declared deprecated
1> \consolegunieapig\consolegunieapig\consolegunieapig.cpp(124) : see declaration of ‘OldFunction’
1>        Message: ‘******OldFunction is deprecated, start using NewFunction******’
1>\consolegunieapig\consolegunieapig\consolegunieapig.cpp(145) : warning C4996: ‘OldClass’ was declared deprecated
1>\consolegunieapig\consolegunieapig\consolegunieapig.cpp(128) : see declaration of ‘OldClass’
1>        Message: ‘******OldClass is deprecated, start using NewClass******’

Using #pragma deprecated

Another option to deprecate a class/struct/function is to use the #pragma deprecated compiler directive.

The main difference is that using __declspec(deprecated) we can selective deprecate functions but with #pragma deprecated every function with that particular name is marked as deprecated. With #pragma deprecated you can even deprecate a macro.

This is how we use #pragma deprecated

void OldFunction() {}
void OldFunction( int i ) {}
class OldClass {};

// Note that both versions of OldFunction will be marked as deprecated.
#pragma deprecated(OldFunction,OldClass);
Aug 012008
 

Having trouble finding out your VC++ compiler version number? Let me help you out. 🙂 Open command prompt type and type in

cl.exe /?

Relevant part, as shown for me, is pasted here. My current compiler is VC6.

Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 12.00.8804 for 80×86 Copyright (C) Microsoft Corp 1984-1998. All rights reserved.

Important pieces are in bold. Compiler is a 32-bit one and it’s version is 12.00.8804. So _MSC_VER will be 1200. Also the copyright year is important 1984-1998, this compiler was released in 1998, 1984 tells the year when Microsoft(R) Corp was registered as a company. 😉

So if you want to compile some piece of code just for VC6 compiler then you can add conditional compilation statements likewise…

#if _MSC_VER == 1200
  // Some VC6 specific code
#endif

For VC8, above copyright message looks like this for me…

Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 14.00.50727.42 for 80×86 Copyright (C) Microsoft Corporation.  All rights reserved.

So _MSC_VER for VC8 will be 1400.

Now you may ask that how can I check full version of my vc++ compiler, for that purpose we have _MSC_FULL_VER macro defined.

#if _MSC_FULL_VER == 140050727
std::cout << "You are using vc8 compiler, version: " << _MSC_FULL_VER; #endif[/sourcecode] Values of _MSC_VER for different VC versions are listed below... VC6 - 1200 VC7 - 1300 VC8 - 1400 VC9 - 1500

Jul 252008
 

Well it was quite easy in VC6 to work with iterators since iterators were actual pointers to internal data, so they could be used interchangeably.

For e.g.

typedef std::vector<int> IntVector;
IntVector IntVecObj;

// Push in a thousand ints
for( int Index = 0; Index < 1000; ++Index )
{
   IntVecObj.push_back( Index + 1 );
}
// Access internal pointer
int *p = IntVecObj.begin();&#91;/sourcecode&#93;

But above code gives error if compiled in VC8! Says cannot convert from vector::iterator type to int*. Mmm, so how can we get the internal pointer? This is what I've done...

&#91;sourcecode language="cpp"&#93;// Following code snippet won't compile in VC6 hence the compilation guard
#if _MSC_VER >= 1400 // VC8 onwards
   int* p = &(*IntVecObj.begin());
   // Or // int* p = IntVecObj.begin()._Myptr;
   ++*p;
#endif

You may ask why I had to take this approach? I am currently migrating a project from VC6 to VC8 hence plenty of code which directly uses pointers as iterators and iterators as pointers, so this helps. 🙂

I’ve got to say it’s a pain to work with new version of these stl classes, of course it could all turn out for good, sigh! anyway 🙁