gpt4 book ai didi

c - strlen(s) 和 (strlen)(s) 之间有什么区别吗?

转载 作者:太空宇宙 更新时间:2023-11-03 23:48:11 25 4
gpt4 key购买 nike

<分区>

在 bstrlib.c(bstring 库)中,有几个地方将函数调用放在圆括号中。目的是什么?

代码片段:

bstring bfromcstr (const char * str) {
bstring b;
int i;
size_t j;

if (str == NULL) return NULL;
j = (strlen) (str);
i = snapUpSize ((int) (j + (2 - (j != 0))));
if (i <= (int) j) return NULL;

b = (bstring) bstr__alloc (sizeof (struct tagbstring));
if (NULL == b) return NULL;
b->slen = (int) j;
if (NULL == (b->data = (unsigned char *) bstr__alloc (b->mlen = i))) {
bstr__free (b);
return NULL;
}

bstr__memcpy (b->data, str, j+1);
return b;
}

我自己尝试了一些东西:

int main(){
char *s = {"hello"};
int length = strlen(s);
//int length = (strlen)(s); // this produce the same output as the above line
printf("length = %d\n", length);
return 0;
}

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