unsigned long and uint32_t?

coder picture coder · Aug 6, 2018 · Viewed 8.5k times · Source

I'm studying socket programming and I learned inet_addr function. But I'm confused how can I handle in_addr_t type.

inet_addr function returns in_addr_t type which is uint32_t, then do I have to use uint32_t type variable to handle it?

In the book, example handles it as unsigned long type, but I don't understand why this way is used.

unsigned long conv_addr = inet_addr(addr1); // unsigned long == uint32_t?

Answer

Eric Postpischil picture Eric Postpischil · Aug 6, 2018

You do not have to use uint32_t to handle the value returned from inet_addr. You can use any type that can represent any value that might be returned or that you might use in a calculation. But why not use the uint32_t or the in_addr_t type?