When I try to compile a function with return type bool in GCC compiler, the compiler throws me this error.
error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘comp’
But when I change the return type to int, it is getting compiled successfully.
The function is as below.
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;
}
Here I am comparing two linked lists. Is bool return type supported in C or not?
booldoes not exist as a keyword pre-C99.In C99, it should work, but as @pmg points out below, it’s still not a keyword. It’s a macro declared in
<stdbool.h>.