簡體   English   中英

static size_t strnlen(const char * s,size_t max) - 為什么靜態返回值?

[英]static size_t strnlen(const char *s, size_t max) — why a static return value?

我可能會瘋了,但我不認為我曾經在c ++中看到過這種情況(盡管我的參考代碼是在C中)。 為什么這里代碼的返回值有靜態,它有什么影響? 我不認為我曾經見過類范圍之外的靜態函數(但顯然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不在返回類型上,而是在函數定義上

靜態函數基本上沒有外部鏈接它們只對同一文件中的其他函數可見。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM