Inline or Not Inline

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…

0

Visual C++ Shanghai Team Blog is Online

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…

0

Output Text in Unicode

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…

0

IDA Pro 5.5 is released

IDA Pro 5.5 ships 12th of June 2009. The change list is here: http://www.hex-rays.com/idapro/55/index.htm

1

Detect Shift Overflow

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…

0

Recursive Algorithm in C++

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…

1

Measure Initialization Time of Global Variables

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,…

1

Optimize Your Code: Matrix Multiplication

Matrix multiplication is common and the algorithm is easy to implementation. Here is one example: Version 1:template<typename T>void SeqMatrixMult1(int size, T** m1, T** m2, T** result){    for (int i = 0; i < size; i++) {        for (int j = 0; j < size; j++) {            result[i][j] = 0;            for (int k = 0; k…

8

C++ Template Trick: Detecting Object Slicing

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…

2

C++ Template Trick: Detecting the Existence of Class Member at Compile Time

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…

1