Year: 2009

What is inline? This keyword is mainly used to ask the compiler to inline substitution of the function body at the point of call. Like ‘register’, this is only a suggestion to the compiler. Modern compiler can handle inlining using advanced heuristic to get better size / performance balance without the suggestion from the developer. So most…

I’m glad that our team blog is now online (http://blogs.msdn.com/vcshblog/). It is in Chinese and is targeted to Chinese developers. We will write technical articles related to our work in Shanghai and also translate articles on VCBlog into Chinese. Here are articles posted by our team on VCBlog: /DYNAMICBASE and /NXCOMPAT Linker warning LNK4221, and…

According to C standard, it only supports output text in MBCS (Multi-Byte Character String): n1124.pdf, 7.19.3/12 The wide character output functions convert wide characters to multibyte characters and write them to the stream as if they were written by successive calls to the fputwc function. Each conversion occurs as if by a call to the…

This is an intellectual exercise: when shifts a 32-bit unsigned integer in C++, how to detect whether the calculation overflows efficiently? Here is the function prototype. shl_overflow will return true if v << cl overflows (cl is between 0 and 31. And we assume that sizeof(unsigned long) == 4 and sizeof(unsigned long long) == 8).bool…

Many recursive algorithms have initial parameters. For example, Fibonacci Number is defined as: Fn = Fn-1 + Fn-2, with F1 = F2 = 1. By giving different values to F1 and F2, we can generate different sequence of numbers. 1. If we implement the algorithm using functions, we have to either define these parameters as…

NOTICE: The technique describes in the article may not be supported in future release of VC. You should not use it in production code There are two kinds of initialization in C++: static initialization and dynamic initialization. According to the standard, static initialization shall always be performed before any dynamic initialization takes place. In VC,…

Object slicing often happens when you pass the object by value. Compiler will do implicitly conversion from derived to base for you without any warning message. If you want to detect object slicing, you’re on your own. However, template can help you. Because object slicing will call copy constructor of base class, what you can…

C++0x will provide a full set of type traits helpers to ease generic programming. However, there is no support for the detection of class members. The general problem is hard. Here we will try to tackle the more specific version: detecting the class member with given name and type. In C++, function overload is one…