2009/10/17 David Brownell <[email protected]>

>
> What's with the strange "(HANDLE)(0 + _get_osfhandle())"?
>
> The "0 +" is mutant...
>

Yeah. The problem here is that HANDLE is typedef'd as void* (in winnt.h),
whereas _get_osfhandle() returns a long (
http://msdn.microsoft.com/en-us/library/ks2530z6.aspx), and gcc insists on
returning a warning when casting a 32 bit long into a 64 bit pointer ("cast
to pointer from integer of different size").
The most elegant way I found to avoid that warning is to do an arithmetic
operation first.

Of course one has to wonder why a function that is meant to return a handle
does not actually return a type HANDLE...

The only other way I see to do it is to add idefs for MINGW64 so that we
cast _get_osfhandle() to a long long first.

What do you think is the worst that could happen by issuing a "0 +" on an
integer value that is meant to be used as a valid pointer in the first
place? _get_osfhandle is meant to provide a pointer (handle) that is valid
for the OS it's actually being executed in. It's just that for whatever
reason, the makers of that function decided to return anything but a handle
but I still think what we're doing here should be pretty safe.

Regards
_______________________________________________
Openocd-development mailing list
[email protected]
https://lists.berlios.de/mailman/listinfo/openocd-development

Reply via email to