當我嘗試在GCC編譯器中編譯返回類型爲bool
的函數時,編譯器會引發此錯誤。是C中允許的布爾返回類型嗎?
error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘comp’
但是,當我改變返回類型爲int
,它是越來越成功編譯。
功能如下。
bool comp(struct node *n1,struct node *n2)
{
if(n1 == NULL || n2 == NULL)
return false;
while(n1 != NULL && n2 != NULL)
{
if(n1->data == n2->data)
{ n1=n1->link; n2=n2->link; }
else
return false;
}
return true;
}
這裏我比較兩個鏈表。 C中是否支持bool返回類型?
什麼是'foo'? –
對不起。我編輯過。現在檢查。 – Vivek
如果n1和n2都爲NULL,則可能要返回true。 – eyalm