I'd cast fd to uintptr_t here.  Casts from unsigned to signed types of equal or smaller width are implementation defined.