cast to correct type during malloc