Constructor representation in C

In C++, objects may be allocated on the heap or the stack. This has implications in the mapping from a C++ constructor to an initialization function in C.

A::A(int x)
{
m_x = x;
m_z = 0;
}

The mapped constructor takes an additional this pointer. A NULL is passed as the this pointer when the object has to be allocated on the heap. A valid stack address is passed when an object is on the stack.

If a NULL pointer is passed to the construction function, it allocates memory before performing the initialization.