J'écris un vecteur en C. La fonction CVectorSearch utilise bsearch si elle est triée, et lfind si elle n'est pas triée. Pourquoi est-ce que j'obtiens l'avertissement "assignation fait un pointeur d'entier sans un cast" quand j'appelle lfind? Il semble fonctionner même lorsque lfind est utilisé.pointeur d'entier sans avertissement cast lors de l'appel de lfind
typedef struct
{
void *elements;
int logicalLength;
int allocatedLength;
int elementSize;
} CVector;
typedef void (*CVectorFreeElemFn)(void *elemAddr);
int CVectorSearch(const CVector *v, const void *key,
CVectorCmpElemFn comparefn,
int startIndex, bool isSorted)
{
void * found;
int elemSize = v->elementSize;
int length = v->logicalLength;
void *startAddress = (char*)v->elements + startIndex*elemSize;
if(isSorted)
found = bsearch(key, startAddress, length, elemSize, comparefn);
else
found = lfind(key, startAddress, &length, elemSize, comparefn);
if(found)
return ((char*)found - (char*)v->elements)/elemSize;
else
return -1;
}
modifier: Maintenant que j'ai inclus search.h je reçois:
warning: passing argument 3 of 'lfind' from incompatible pointer type
Le programme fonctionne toujours correctement, cependant.