New commit from the office.
Memory
=============
size_t and unsigned long
-------
On windows 64bit, sizeof(unsigned long) == 32 and sizeof(size_t) == 64.
On linux 64bit, sizeof(unsigned long) == sizeof(size_t) == 64
intptr_t and uintptr_t (inttypes.h): ints that guarantee to hold a pointer.
ptrdiff_t: type returned by arithmetic differencing two pointers.
::operator new and ::operator delete
-------
[Stroustrup3rd, 19.4.5, p576]
Can be redefined, to use posix_memalign and free
The redefinition can be done as class members [Stroustrup3rd, 15.6, p421]
class A
{
static void* operator new (size_t size);
static void operator delete (void *p);
};
int main()
{
A *p = new A; // calls A::new;
delete p; // calls A::delete;
}
The redefinition can't be done on other namespace than the global, if not
done in a class.
Prototypes for the new/delete Operators
--------------
void* operator new(size_t);
void operator delete(void* );
void* operator new[](size_t);
void operator delete[](void* );
#include <new> // has set_new_handler(), for bad_alloc handling.
Exceptions
=================
<stdexcept>:
logic_error
domain_error
invalid_argument
length_error
out_of_range
runtime_error
range_error
overflow_error
underflow_error
Casting
=================
Explicit type conversion [Stroustrup3rd, 6.2.7, p130]
static_cast - converts between related types (pointer to another, enum to int,
float to int,...). Has minimal type checking, and are often portable.
reinterpret_cast - converts between unrelated types (pointer to int, pointers
to functions [7.7], ...).
No type checking. Rarely portable.
dynamic_cast - run-time checked conversion.
const_cast - for removing const qualifiers.
(Type) exp - Unspecified combination of static+reinterpret+dynamic casts,
to get the cast done.