
At Thu, 02 May 2013 07:54:47 -0600, Eric Blake wrote:
[1 <multipart/signed (7bit)>] [1.1 <text/plain; UTF-8 (quoted-printable)>] On 05/02/2013 06:05 AM, Guido Günther wrote:
This fixes the build on kFreeBSD that otherwise fails with:
util/virthreadpthread.c: In function 'virThreadSelfID': util/virthreadpthread.c:222:27: error: cast from function call of type 'pthread_t' to non-matching type 'void *' [-Werror=bad-function-cast] --- I'm unsure why we'd need the cast to (void*) first.
EVERYTHING should be castable to void*. That's lame that your compiler is refusing to cast pthread_t.
I'm thinking that the solution will require writing a union, assign to the pthread_t member of the union, and read out the int member, as the only way we're going to shut up compilers. We KNOW that casting pthread_t isn't portable; but all we really want is a few bits that are hopefully likely enough to be unique to make the use of virThreadSelfID useful in debug messages. We aren't relying on the conversion being a 1:1 mapping nor on trying to reverse the mapping.
Since the warning only ever refers to directly casting a function return value, wouldn't it suffice to introduce a (properly typed) variable first assigning the function result? pthread_t self = pthread_self(); return (int)(intptr_t)self; Just my 2¢ -- AV-Test GmbH, Henricistraße 20, 04155 Leipzig, Germany Phone: +49 341 265 310 19 Web:<http://www.av-test.org> Eingetragen am / Registered at: Amtsgericht Stendal (HRB 114076) Geschaeftsfuehrer (CEO): Andreas Marx, Guido Habicht, Maik Morgenstern