gpt4 book ai didi

c - static size_t strnlen(const char *s, size_t max) -- 为什么是静态返回值?

转载 作者:太空狗 更新时间:2023-10-29 16:08:52 26 4
gpt4 key购买 nike

我可能要疯了,但我认为我从未在 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);
}

来自 http://www.zeuscat.com/andrew/software/c/strnlen.c .

最佳答案

static不在返回类型上,而是在函数定义上

静态函数基本上没有外部链接,它们只对同一文件中的其他函数可见。

关于c - static size_t strnlen(const char *s, size_t max) -- 为什么是静态返回值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8884255/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com