ueach
est une fonction qui effectue une boucle dans une chaîne Unicode et exécute le rappel sur chaque caractère en lui passant une chaîne de caractère unique.Avertissement de pointeur de fonction étrange en C
string ueach(string s, void *function(string)) {
unsigned long i;
for (i = 0; i < s.length; i++)
function(uchar(s, i));
}
Si j'ai un rappel testing
:
void testing(string c) {
puts(utoc(c));
}
qui imprime le caractère donné (utoc
convertit la chaîne Unicode UTF-8 char *
) tout fonctionne très bien. Le code:
string a = ctou("Hello, world!");
ueach(a, &testing);
Cependant, je reçois cet avertissement:
test.c: In function ‘main’:
test.c:8: warning: passing argument 2 of ‘ueach’ from incompatible pointer type
ulib:171: note: expected ‘void * (*)(struct string)’ but argument is of type ‘void (*)(struct string)’
Si je mets entre parenthèses autour de la partie de la fonction du prototype ueach
comme ceci:
string ueach(string s, void (*function)(string)) { ... }
il fonctionne très bien aussi, sans avertissement. Quelle est la différence entre void * (*)(struct string)
et void (*)(struct string)
?
Quelle est la différence entre void *function(string)
et void (*function)(string)
?