views:

45

answers:

2
warning: passing argument 1 of 'bsearch' makes pointer from integer without a cast

and the corresponding code is

Parent =bsearch((const size_t)ParentNum, ClauseVector, Size,
                  sizeof(CLAUSE),pcheck_CompareNumberAndClause);

the compilar is gcc.

here CLAUSE is defined as *CLAUSE.

@Paul This following more information has been added:

The change i made to the above code is :

Parent =bsearch((uintptr_t*)(size_t)(const)ParentNum,(uintptr_t*) ClauseVector,Size,
                  sizeof(CLAUSE),pcheck_CompareNumberAndClause);

After compiling i got following warning:

warning: type defaults to 'int' in declaration of 'type name'

how can i correct it?

A: 

The first argument to bsearch() should be a pointer to a value you want to search. I don't know what ParentNum is, but with your cast to const size_t, it is not of a pointer type, so you get the warning. The first argument to bsearch in your case should be a CLAUSE * value that you want to search in ClauseVector.

here CLAUSE is defined as *CLAUSE.

doesn't make any sense.

Alok
+1  A: 

The signature for bsearch is:

void * bsearch(const void *key, const void *base, size_t nel, size_t width, int (*compar) (const void *, const void *));

It should be pretty obvious that the first parameter (at least) in your code is incorrect.

Without seeing the rest of your code it's hard to fix this but it should probably be something like:

Parent = bsearch(&ParentNum, (void *)ClauseVector, Size,
                  sizeof(CLAUSE), pcheck_CompareNumberAndClause);

It would help if you posted the definitions of ParentNum, ClauseVector, Size, CLAUSE, etc.

Paul R
i made following changes to tha code Parent =bsearch((uintptr_t*)(size_t)(const)ParentNum,(uintptr_t*) ClauseVector,Size, sizeof(CLAUSE),pcheck_CompareNumberAndClause);and i got following warning. warning: type defaults to 'int' in declaration of 'type name'.Is this the right approach to deal with the this warning?
thetna
Put this info in your question (i.e. edit it) - it's hard to read code in comments.
Paul R
@Paul, thanks a lot. it really worked.
thetna