我在Objective-C中编程,但是我想写交流功能来提高性能。我写了下面这篇文章的代码,但编译保持与以下错误回来:'function'之前预期的特定限定符列表和期望的'=',',';','asm'或'__attribute__'在'函数'之前
error: expected specific-qualifier-list before 'bool'
error: expected '=', ',', ';', 'asm' or 'attribute' before 'addToBoolArray'
structs.h:
typedef struct boolArray{
bool *array;
int count;
} boolArray;
bool addToBoolArray(boolArray *bArray, bool newBool)
structs.c:
#import "structs.h"
bool addToBoolArray(boolArray *bArray, bool newBool)
{
if(bArray->count > 0){
bArray->array = realloc(bArray->array,(bArray->count+1)*sizeof(bool));
else{
bArray->array = (bool *)malloc(sizeof(bool));
}
if(bArray->array == NULL)
return false;
bArray->array[bArray->count] = newBool;
bArray->count++;
return true;
}
我我发现很多关于这个错误的论坛主题,但他们都没有解决我的问题。有任何想法吗?
谢谢
在C99有预定义的类型'_Bool'它,无需任何包含(#include)头工作。 – pmg
是的,当然它只是'typedef _Bool bool'。但在实践中,我从未见过任何人直接使用'_Bool',就像没有人直接使用'_Complex'一样。这样做的唯一原因是为了避免引入新的关键字,这些关键字可能会与已被广泛使用的关键字发生冲突。 –