xcode 'function' 之前的预期特定限定符列表和 'function' 之前的预期 '=', ',', ';', 'asm' 或 '__attribute__'

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1931472/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 19:00:58  来源:igfitidea点击:

expected specific-qualifier-list before 'function' and expected '=', ',', ';', 'asm' or '__attribute__' before 'function'

cobjective-cxcode

提问by Justin

I am programming in Objective-C but I would like to write a c function to increase the performance. I have written the code below this post but the compile keeps coming back with the following error:

我正在使用 Objective-C 进行编程,但我想编写 ac 函数来提高性能。我在这篇文章下面写了代码,但编译不断返回以下错误:

error: expected specific-qualifier-list before 'bool'

error: expected '=', ',', ';', 'asm' or 'attribute' before 'addToBoolArray'

错误:'bool' 之前的预期特定限定符列表

错误:在“addToBoolArray”之前应为“=”、“、”、“;”、“asm”或“属性

structs.h:

结构体.h:

typedef struct boolArray{
bool *array;
int count;
} boolArray;

bool addToBoolArray(boolArray *bArray, bool newBool)

structs.c:

结构体.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;
}

I've found many forum threads about this error but none of them seem to address my issue. Any ideas?

我找到了许多关于此错误的论坛主题,但似乎没有一个能解决我的问题。有任何想法吗?

Thank you

谢谢

回答by Pavel Minaev

There's no booltype in C89 or Objective-C.

boolC89 或 Objective-C 中没有类型。

For plain C89, typically intis used.

对于普通的 C89,通常int使用。

For C99, you can do:

对于 C99,您可以执行以下操作:

#include <stdbool.h>

For Objective-C, it seems that there's a typedef for BOOL, and constants TRUEand FALSE, is NSObject.h.

对于Objective-C,似乎有一个typedef for BOOL, and constants TRUEand FALSE,是NSObject.h。

回答by nos

You should probably use BOOLfrom <objc.h>. If you want to use (the C99 type) bool, include <stdbool.h>.

您可能应该使用BOOLfrom <objc.h>。如果要使用(C99 类型)bool,请包含<stdbool.h>.

You are also missing a ;after the declaration of addToBoolArrayin your header file.

您还缺少头文件中;的声明之后的addToBoolArray

回答by Vincent Gable

If you are trying to increase performance, you might want to use a bit vectorinstead of an array of bools…

如果您想提高性能,您可能需要使用位向量而不是bools数组...