2
在bstrlib.c(bstring庫)中,有幾個地方圍繞函數調用放置括號。什麼目的?strlen(s)和(strlen)(s)之間是否有區別?
代碼片段:
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;
}
@NPE,我應該刪除嗎? – drdot
就我個人而言,我會放棄它,但這取決於你。 – NPE