I was trying to figure out a piece of code which constructs a hostent object, more specifically, the part of it’s work that populates the h_addr_list array.
I was confused by the fact that the values that were assigned into the array were cast to char*, seeing as this array has nothing to do with strings as far as I read.
I noticed that the h_addr_list array is actually typed as char**.
The only place I saw that takes note of this fact is section 9.7 in beej’s Guide to Network Programming, but even there there’s no explanation on why is it typed so.
Is there a reason that h_addr_list is typed as char** and not void*/void** (or anything else that might be a bit more informative)?
char *needn’t necessarily refer to a C string, but also to a chunk of memory of known length that needs to be addressed by byte, presumably because it arrives from the network.Before types like
int8_tanduint8_twere added to C99,char *was the only practical way to refer to a contiguous byte array. In fact,struct hostentpredates C89 which formalized thevoidtype. If written today, the field would be declared asvoid **or possiblyuint8_t **.