function pointer reinterpret_cast

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 use func, 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);
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值