htonl, htons, ntohl, ntohs - convert values between host and network byte order
#include <arpa/inet.h>
uint32_t htonl(uint32_t hostlong);
uint16_t htons(uint16_t hostshort);
uint32_t ntohl(uint32_t netlong);
uint16_t ntohs(uint16_t netshort);
reinterpret_cast conversion
Syntax
reinterpret_cast < new_type > ( expression )
Returns a value of type new_type.
function pointer
“Why function pointer does not require dereferencing?”
Because the function identifier itself is actually a pointer to the function already:
*4.3 Function-to-pointer conversion*
§1 An lvalue of function type T can be converted to an rvalue of type “pointer to T.” The result is a pointer to the function.“Why dereferencing a function reference doesn’t result in an error?”
Basically you can look at defining a reference as defining an alias (alternative name). Even in the standard in 8.3.2 References in part addressing creating a reference to an object, you will find:
“a reference can be thought of as a name of an object.”So when you define a reference:
void (& f_ref)(int) = func;
it gives you the ability to use
f_ref
almost everywhere where it would be possible to usefunc
, which is the reason why:
f_ref(1); (*f_ref)(4);
works exactly the same way as using the
func
directly:
func(1); (*func)(4);