C++ Tips from Thinking in C++(2)

Continued from C++ Tips from Thinking in C++(1)
5. Const pointer VS. Pointer to const
If you want to prevent any changes to the element you are pointing to, that is “Pointer to const”, you write a definition like this:

const int* u;

Starting from the identifier, we read “u is a pointer, which points to a const int.”
Here’s the mildly confusing part. You might think that to make the pointer itself unchangeable, that is, to prevent any change to the address contained inside u, you would simply move the const to the other side of the int like this:

int const* v;

Unfortunately, I will tell you that it’s wrong! Actually “const int* u;EQUALSint const* v;“. However, the way it actually reads is “v is an ordinary pointer to an int that happens to be const.” That is, the const has bound itself to the int again, and the effect is the same as the previous definition. So to avoid confusion, you should abandon the second form.
So how to make a “const pointer”? To make the pointer itself a const, you must place the const specifier to the right of the *, like this:

int d = 1;
int* const w = &d;

Now it reads: “w is a pointer, which is const, that points to an int.” Because the pointer itself is now the const, the compiler requires that it be given an initial value that will be unchanged for the life of that pointer.
You can also make a const pointer to a const object using either of two legal forms:

int d = 1;
const int* const x = &d; // (1)
int const* const x2 = &d; // (2)

Now neither the pointer nor the object can be changed.
6. Standard argument passing
In C it’s very common to pass by value, and when you want to pass an address your only choice is to use a pointer. However, in C++, Your first choice when passing an argument is to pass by reference, and by const reference at that. But, passing by reference produces a new situation that never occurs in C: a temporary, which is always const, can have its address passed to a function.So to allow temporaries to be passed to functions by reference, the argument must be a const reference.The following example demonstrates this: (c++11 introduced

class X {};
X f() { return X(); } // Return by value
void g1(X&) {} // Pass by non-const reference
void g2(const X&) {} // Pass by const reference

int main() {
// Error: const temporary created by f():
//! g1(f());
// OK: g2 takes a const reference:
} ///:~

f( ) returns an object of class X by value. That means when you immediately take the return value of f( ) and pass it to another function as in the calls to g1( ) and g2( ), a temporary is created and that temporary is const. Thus, the call in g1( ) is an error because g1( ) doesn’t take a const reference, but the call to g2( ) is OK.

GNU Automake tools Quick Reference(Autoconf)

Because of the diversity of the Unix system, the famous ‘configure’ script should be runned before compiling the source code on the system. The script check your system environment such as where your library locate and help you decide which part of the source code should be complied. This small simple qucik refrence is made by myself when I started to work as Software Engineer.

Continue reading “GNU Automake tools Quick Reference(Autoconf)”

Like new cufflinks and studs for Tuxedo and formal wear for sale

I am selling one of my cufflinks and studs set which is only used for once.

タキシード用カフス&スタッド(黒) フリー 3800 円 

2か月前に新品購入したので、綺麗な状態です。すぐお譲りできます。連絡先 080 3916 1983

This cufflinks and studs set for your formal wear is used once only – so it deserves the name” almost like new”. (I can speak Japanese if we do local deal and meet up around Shibuya, Shinjuku area. Please contact me at 080 3916 1983)



This set is perfect for you at a black-tie event and most other men are poorly dressed in their tuxedos.  (Local deal in Tokyo is preferred, though international buyer is posisble but based on good mutual good faith if you trust me 🙂

Price is 3800 JPY (purchased originally at Rakuten at 5900 JPY, please see the link http://item.rakuten.co.jp/auc-tradhousefukiya/cs01/