2015年3月12日 星期四

Modern C++ in embedded systems Part 1 : Myth and Reality


Modern C++ in embedded systems Part 1 : Myth and Reality
by 

References
A reference in C++ is physically identical to a pointer. Only the syntax is different. References are safer than pointers because they can’t be null, they can’t be uninitialized, and they can’t be changed to point to something else. The closest thing to a reference in C is a const pointer. Note that this is not a pointer to a const value, but a pointer that can’t be modified. Listing 3 shows a C++ code fragment with a reference. 

     // C++ reference example
     void accumulate(int& i, int j) {
         i += j;
     }


Listing 3: C++ reference


沒有留言: