static size_t strnlen(const char *s, size_t max) -- 为什么是静态返回值?
我可能会发疯,但我认为我从未在 C++ 中见过这个(尽管我的参考代码是 C 语言)。为什么这里代码的返回值有一个static,有什么影响?我认为我从未见过类范围之外的静态函数(但显然 C 没有类,这可能具有不同的语法含义)。
/* just like strlen(3), but cap the number of bytes we count */
static size_t strnlen(const char *s, size_t max) {
register const char *p;
for(p = s; *p && max--; ++p);
return(p - s);
}
I might be going insane, but I don't think I've ever seen this in c++ (though my reference code is in C). Why is there a static on the return value of the code here and what impact does it have? I don't think I've ever seen a static function outside class scope (but obviously C doesn't have classes and this probably has a different syntactical meaning).
/* just like strlen(3), but cap the number of bytes we count */
static size_t strnlen(const char *s, size_t max) {
register const char *p;
for(p = s; *p && max--; ++p);
return(p - s);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
静态不在返回类型上,而是在函数定义上 。
静态函数基本上没有外部链接,它们仅对同一文件中的其他函数可见。
the static is not on the return type but on the function definition.
static functions don't have external linkage basically they are only visible to other functions in the same file.