previous | start | next

Casts

We can use the void * as the type of pointers to the allocated/free parts or to the header/footer parts, but using casts:

        size_t hd; // the header integer
        size_t sz; // for the size of the block
        int a;     // 1 if block is allocated, else 0


        void *p;  // Assume this points to the header
        
        hd = *(size_t *) (p)
        sz = hd & ~0x7;
        a =  hd & 0x1;
     

This would result in some pretty awful looking code, easily susceptible to typos.



previous | start | next