background preloader

C++

Facebook Twitter

Papers

"stdint" for Visual C++ WIN32 API. Libraries. Tpl: serialization for C programs. Implementing a simple smart pointer in c++ Introduction What are smart pointers? The answer is fairly simple; a smart pointer is a pointer which is smart. What does that mean? Actually, smart pointers are objects which behave like pointers but do more than a pointer. These objects are flexible as pointers and have the advantage of being an object (like constructor and destructors called automatically).

Problems with pointers What are the common problems we face in C++ programs while using pointers? Char* pName = new char[1024]; … SetName(pName); … … if(null ! How many times have we found a bug which was caused because we forgot to delete pName. We shall start with a realistic example. Now we shall write the client code to use Person. void main() { Person* pPerson = new Person("Scott", 25); pPerson->Display(); delete pPerson; } Now look at this code, every time I create a pointer, I need to take care of deleting it.

Void main() { SP p(new Person("Scott", 25)); p->Display(); } Note the following things: Interface for a smart pointer. Tutorial: Using C/C++ and Fortran together. Order of multi dimensional arrays in C/C++ is the opposite of FORTRAN. Native FORTRAN layout (collumn-major order): INTEGER A(2,3) Or INTEGER A(2,2,2) Native C layout (row-major order) is NOT equivalent to the FORTRAN layout: int a[2][3]; Thus: Equivalent multidimension arrays: FORTRAN 77: INTEGER I(2,3,4) FORTRAN 90: INTEGER, DIMENSION(2,3,4) :: I C: int i[4][3][2]; Accessing a FORTRAN array in C: Native FORTRAN: Native C: C array a[3][2] memory layout: In FORTRAN 90, also check out the "RESHAPE" directive. Fortran subroutines are the equivalent of "C" functions returning "(void)".

Note: The entry point names for some FORTRAN compilers have an underscore appended to the name. The f77 comiler flags "-fno-underscore" and "-fno-second-underscore" will alter the default naming in the object code and thus affect linking. Note: The case in FORTRAN is NOT preserved and is represented in lower case in the object file. Man pages: Character variables: C expects strings to be null-terminated.