c - 这个功能有什么问题?

标签 c objective-c

编译器对此提示:

int randomSort(id obj1, id obj2, void *context) { // first line
    return (arc4random()%3 - 1);
}

第一行:

_cmd undeclared

'self' undeclared (first use in this function)

当我在这里不使用 arc4random() 时,即只返回 1,一切都很好。我在这个文件中还有其他 c 函数,它们使用 arc4random() 没有问题。

有什么想法吗?

最佳答案

在使用arc4random()函数前需要告知其签名,即

int arc4random();  // or whatever it looks like

或者包含/导入适当的头文件。如果您的 randomSort 函数确实是第一行,那么显然之前没有一行,因此您不可能包含/导入它(这里不考虑预编译头文件)。

关于c - 这个功能有什么问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3174447/

相关文章:

c - c语言tiff图像代码

ios - 自定义 UIBarButtonItem

ios - 我如何创建一个使用 CCSpriteFrameCache 和 CCSpriteBatchNode 对象的 CSSprite 类?

iphone - 使用 objective-c 程序在 safari 中打开和关闭 url

c - 如何在 C 中反转多维数组?

c - 数组名称如何具有其地址以及其中的第一个元素?

objective-c - 属性字符串超链接未显示正确的光标

iphone - 如何使用 r、g、b、a 矩阵将调整 'curve' 应用于图像?

c - Xcode 找不到第三方库

c - For循环忽略第一行,在C中第一次循环执行后