I'm a developer at C++ Shanghai team. I'm interested in everything related to C++
Browse by Tags
All Tags »
C++ (RSS)
-
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 Read More...
|
-
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 Read More...
|
-
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 Read More...
|
-
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, Read More...
|
-
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; Read More...
|
-
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. Read More...
|
-
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 Read More...
|
-
C++0x will be released in the near future. Do you know the changes of standard library? Here is a list of changes that I've collected (minor behavior changes and changes related to concepts are not included). 1. New stuff system_error: new header array, Read More...
|
-
MSDN has a page describing various VC extensions. But it is far from complete. I've collected a list of nonstandard extensions provided by VC, some of them are evil . If you want to write standard conformant C++ code, you'd better be aware of these extensions Read More...
|
-
In C++, it is well-known that the data in the vector is contiguous. To be more specific, here is the quotation from the standard (C++03, 23.2.4/1) The elements of a vector are stored contiguously, meaning that if v is a vector<T, Allocator> where Read More...
|
-
As the designer of base class, you may hesitate whether to use private or protect access control. Then, let's try the following examples: 1. Call protected member function #include <cstdio> class A { protected : void b() {printf( "Oops!\n" );} }; Read More...
|
-
Obfuscation is widely used to protect your code from reverse engineering. Here is one example which takes advantage of indirected call and opcode overlap in X86: __declspec ( naked ) void Fun1() { __asm { //obfuscation chunk call LABEL1 LABEL1: pop eax Read More...
|
-
Playing with the compiler is interesting. One challenge for the compiler writer is compilation performance. There're many kinds of C++ code which are the nightmare for the compiler. Now let's go! 1. Preprocess a. Self Inclusion (GCC only) Normally, the Read More...
|
-
Someone may wonder what the difference is between Debug and Release mode, and whether it is possible to mix them. Here is one example: http://forums.msdn.microsoft.com/en-US/vcgeneral/thread/775ce067-b225-4141-8b86-2d7e9b61db97/ syperk said: "As a result, Read More...
|
-
In VC STL, there are two macros called "_HAS_IMMUTABLE_SETS" and "_HAS_STRICT_CONFORMANCE" which are defined in yvals.h. They are related to some defects in the C++ standard 2003. 1. _HAS_IMMUTABLE_SETS will influence the constness of set::iterator. Associative Read More...
|