Gcc 编译时收到以下警告
对应的代码是Gcc 编译时收到以下警告,gcc,compiler-warnings,Gcc,Compiler Warnings,对应的代码是 warning: passing argument 1 of 'bsearch' makes pointer from integer without a cast 编译器是gcc 这里的子句定义为*子句 @Paul补充了以下更多信息: 我对上述代码所做的更改是: Parent =bsearch((const size_t)ParentNum, ClauseVector, Size, sizeof(CLAUSE),pcheck_CompareN
warning: passing argument 1 of 'bsearch' makes pointer from integer without a cast
编译器是gcc
这里的子句定义为*子句
@Paul补充了以下更多信息:
我对上述代码所做的更改是:
Parent =bsearch((const size_t)ParentNum, ClauseVector, Size,
sizeof(CLAUSE),pcheck_CompareNumberAndClause);
编译后,我得到以下警告:
Parent =bsearch((uintptr_t*)(size_t)(const)ParentNum,(uintptr_t*) ClauseVector,Size,
sizeof(CLAUSE),pcheck_CompareNumberAndClause);
如何更正?b搜索()的第一个参数应该是指向要搜索的值的指针。我不知道什么是
ParentNum
,但是当您强制转换为const size\u t
时,它不是指针类型,因此您会收到警告。在您的案例中,bsearch
的第一个参数应该是要在ClauseVector
中搜索的子句*
值
这里的子句定义为*子句
没有任何意义。b搜索的签名是:
warning: type defaults to 'int' in declaration of 'type name'
很明显,代码中的第一个参数(至少)是不正确的
如果看不到代码的其余部分,则很难修复此问题,但可能应该是这样的:
void * bsearch(const void *key, const void *base, size_t nel, size_t width, int (*compar) (const void *, const void *));
如果您发布ParentNum、ClauseVector、Size、子句等的定义,这会有所帮助。我对代码Parent=bsearch((uintpttr\u t*)(Size\u t)(const)ParentNum,(uintpttr\u t*)ClauseVector、Size、sizeof(子句)、pcheck\u comparenumberand子句)做了以下更改;我得到了以下警告。警告:在“类型名称”的声明中,类型默认为“int”。这是处理此警告的正确方法吗?将此信息放入您的问题中(即编辑它)-很难在注释中读取代码。
Parent = bsearch(&ParentNum, (void *)ClauseVector, Size,
sizeof(CLAUSE), pcheck_CompareNumberAndClause);