I want to use the htonl
function in my ruby c extension, but don't want to use any of the other internet stuff that comes with it. What would be the most minimalistic file to #include
that is still portable? Looking through the header files on my computer, I can see that either machine/endian.h
or sys/_endian.h
would let me use them, although I am not sure if that is a good idea.
相关问题
- Multiple sockets for clients to connect to
- What is the best way to do a search in a large fil
- glDrawElements only draws half a quad
- Index of single bit in long integer (in C) [duplic
- Equivalent of std::pair in C
On Windows,
arpa/inet.h
doesn't exist so this answer won't do. The include is:So a portable version of the include block (always better to provide one):
The standard header is:
You don't have to worry about the other stuff defined in that header. It won't affect your compiled code, and should have only a minor effect on compilation time.
EDIT: You can test this. Create two files, htonl_manual.c
and htonl_include.c:
Assemble them at -O1, then take the difference:
For me, the only difference is the filename.