Use the right type for pointers and do correct casts