C语言中的static inline

在阅读Redis源码时,注意到SDS数据结构的头文件中使用了`static inline`关键字。该关键字在C语言中主要控制变量和函数的作用域。`static`使得它们仅在当前编译单元可见,而`inline`则用于请求编译器进行内联展开,以提高效率。了解`translation unit`的概念有助于理解这一特性。
摘要由CSDN通过智能技术生成

今天开始看Redis的源码,其中在最简单的数据结构SDS(Simple Dynamic String)的头文件中声明了以下的函数

static inline size_t sdslen(const sds s) {
    struct sdshdr *sh = (void*)(s-(sizeof(struct sdshdr)));
    return sh->len;
}

看到这段代码楞了一下,之前一直以为inline这个关键词智能在C++中使用,没想到在这里也用到了....Google之。。。

http://stackoverflow.com/questions/7762731/whats-the-difference-between-static-and-static-inline-function

inline instructs the compiler to attempt to embed the function content into the calling code instead of executing an actual call.

For small functions that are called frequently that can make a big perform
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值