On Tue, 2005-03-29 at 17:28 +0200, Fabio Rotondo wrote: > Roland Smith wrote: > [...] suppose you have to write a qsort callback: > > void qsort(void *base, size_t nmemb, size_t size, int(*compar)(const > void *, const void *)); > > suppose the "const void *" is actually an int value. By downcasting it > to int, gcc gives you a warning. it'll be a pointer to an int, of course, not an int. But since an int is smaller than a void *pointer, it'll work fine. The addresses might sometimes overlap, but that's OK. That's why it's declared as a pointer to an object of type "void".
The reason it's a warning and not an error to cast between pointer and integer is that it's sometimes both necessary and correct. More often you should cast between a pointer and a long, of course. Liam -- Liam Quin, W3C XML Activity Lead, http://www.w3.org/People/Quin Pictures from old books: http://www.holoweb.net/~liam/pictures/oldbooks/ IRC (chat) programs: www.ircreviews.org/clients/ _______________________________________________ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list