Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C 斯特伦和斯特伦之间有什么区别吗?_C_Function - Fatal编程技术网

C 斯特伦和斯特伦之间有什么区别吗?

C 斯特伦和斯特伦之间有什么区别吗?,c,function,C,Function,在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 NU

在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;
}
strlen(s)
(strlen)(s)
都是相同的

由于调用strlen()时
strlen()是一个函数,因此无需在函数名周围加括号

有一种叫做函数指针的东西,在声明和调用它们时需要括号


当存在同名宏时,为了区分它们,可以在其周围加上括号

@NPE,我要删除吗?我个人会留下的,但这取决于你。
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;
}