Conversion vers un type non-scalaire
Bonjour,
J'ai un petit problème en essayant de compiler libxml2, je tombe sur cette erreur:
Citation:
[zaour@joker libxml2-2.7.8]$ i486-mingw32-gcc -DHAVE_CONFIG_H -I. -I./include -I./include -D_REENTRANT -DWIN32 -march=x86-64 -mtune=generic -O2 -pipe -mms-bitfields -pedantic -W -Wformat -Wunused -Wimplicit -Wreturn-type -Wswitch -Wcomment -Wtrigraphs -Wformat -Wchar-subscripts -Wuninitialized -Wparentheses -Wshadow -Wpointer-arith -Wcast-align -Wwrite-strings -Waggregate-return -Wstrict-prototypes -Wmissing-prototypes -Wnested-externs -Winline -Wredundant-decls -MT testThreads.o -MD -MP -MF .deps/testThreads.Tpo -c -o testThreads.o testThreads.c
testThreads.c: In function 'main':
testThreads.c:110:6: error: conversion to non-scalar type requested
[zaour@joker libxml2-2.7.8]$
Voici la portion de code qui pose problème. Je ne comprends pas ligne 24 le '(pthread_t) -1'. Qu'est ce que ça signifie ? pthread_t est un type, ça n'est même pas un objet, ni même un nombre, alors pourquoi soustraire ce 1 ? 8O
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
| #ifdef HAVE_PTHREAD_H
static pthread_t tid[MAX_ARGC];
#elif defined HAVE_BEOS_THREADS
static thread_id tid[MAX_ARGC];
#endif
/* ... */
#ifdef HAVE_PTHREAD_H
int
main(void)
{
unsigned int i, repeat;
unsigned int num_threads = sizeof(testfiles) / sizeof(testfiles[0]);
void *results[MAX_ARGC];
int ret;
xmlInitParser();
for (repeat = 0;repeat < 500;repeat++) {
xmlLoadCatalog(catalog);
for (i = 0; i < num_threads; i++) {
results[i] = NULL;
tid[i] = (pthread_t) -1;
}
for (i = 0; i < num_threads; i++) {
ret = pthread_create(&tid[i], NULL, thread_specific_data,
(void *) testfiles[i]);
if (ret != 0) {
perror("pthread_create");
exit(1);
}
}
for (i = 0; i < num_threads; i++) {
ret = pthread_join(tid[i], &results[i]);
if (ret != 0) {
perror("pthread_join");
exit(1);
}
}
xmlCatalogCleanup();
for (i = 0; i < num_threads; i++)
if (results[i] != (void *) Okay)
printf("Thread %d handling %s failed\n", i, testfiles[i]);
}
xmlCleanupParser();
xmlMemoryDump();
return (0);
}
#elif defined HAVE_BEOS_THREADS |
Quelqu'un a -t-il une explication à ça ?
Merci :ccool:
PS. Ah, oui, je suis bête, ils ont voulu caster -1 en pthread_t, j'avais pas compris au début :aie:
Par contre, c'est tout aussi obscure puisque pthread_t est un type opaque (une structure chez moi, en l’occurrence), donc je ne vois pas pourquoi caster 1 en un pthread_t 8O