Re: Fix "warning: cast from pointer to integer of different size"
"Erik de Castro Lopo" <mle+win(a)mega-nerd.com> wrote:
/* get pointer to object containing list element */ #define LIST_ENTRY(elem, type, field) \ - ((type *)((char *)(elem) - (unsigned int)(&((type *)0)->field))) + ((type *)((char *)(elem) - (unsigned long)(&((type *)0)->field)))
It should be replaced with FIELD_OFFSET instead. -- Dmitry.
Dmitry Timoshkov wrote:
"Erik de Castro Lopo" <mle+win(a)mega-nerd.com> wrote:
/* get pointer to object containing list element */ #define LIST_ENTRY(elem, type, field) \ - ((type *)((char *)(elem) - (unsigned int)(&((type *)0)->field))) + ((type *)((char *)(elem) - (unsigned long)(&((type *)0)->field)))
It should be replaced with FIELD_OFFSET instead.
FIELD_OFFSET is defined in include/winnt.h. Now I could include winnt.h into include/wine/list.h but that doesn't seem right. I could also copy it,but having two difinitions of the same macro is also not right. I'm also sure that moving the definition from include/winnt.h to include/wine/list.h will break existing code. Any suggestions for dealing with this? Cheers, Erik -- ----------------------------------------------------------------- Erik de Castro Lopo ----------------------------------------------------------------- "The Internet interprets censorship as damage, and routes around it." -- John Gilmore
"Erik de Castro Lopo" <mle+win(a)mega-nerd.com> wrote:
/* get pointer to object containing list element */ #define LIST_ENTRY(elem, type, field) \ - ((type *)((char *)(elem) - (unsigned int)(&((type *)0)->field))) + ((type *)((char *)(elem) - (unsigned long)(&((type *)0)->field)))
It should be replaced with FIELD_OFFSET instead.
FIELD_OFFSET is defined in include/winnt.h.
Now I could include winnt.h into include/wine/list.h but that doesn't seem right. I could also copy it,but having two difinitions of the same macro is also not right. I'm also sure that moving the definition from include/winnt.h to include/wine/list.h will break existing code.
Any suggestions for dealing with this?
Replacing (unsigned int) cast by (unsigned long) doesn't guarantee anything, long can be a 32-bit entity on a 64-bit platform. -- Dmitry.
Dmitry Timoshkov wrote:
"Erik de Castro Lopo" <mle+win(a)mega-nerd.com> wrote:
FIELD_OFFSET is defined in include/winnt.h.
Now I could include winnt.h into include/wine/list.h but that doesn't seem right. I could also copy it,but having two definitions of the same macro is also not right. I'm also sure that moving the definition from include/winnt.h to include/wine/list.h will break existing code.
Any suggestions for dealing with this?
Replacing (unsigned int) cast by (unsigned long) doesn't guarantee anything, long can be a 32-bit entity on a 64-bit platform.
I'm perfectly happy to accept that, but the real question was, "what is the best way to get FIELD_OFFSET in include/wine/list.h?". I see four options: 0) Include include/winnt.h into include/wine/list.h. Ugly! 1) Copy definition of FIELD_OFFSET macro from include/winnt.h to include/wine/list.h. Ugly! 2) Move the definition of FIELD_OFFSET macro from include/winnt.h to include/wine/list.h. This will probably break existing code. Ugly! 3) Add a definition if FIELD_OFFSET wrapped in #ifndef. This is the least ugly option but would cause surprising results if one or the other was changed. So, to rephrase the question, which of the above would actually be accepted as a patch? If none of them are good enough (highly likely) can someone please suggest an alternative that would be acceptable? Cheers, Erik -- ----------------------------------------------------------------- Erik de Castro Lopo ----------------------------------------------------------------- Journalist: Microsoft CEO Steve Ballmer has finally said Linux is the No. 1 threat to Windows. What's your response to that? Linus : "Tag, you're it." I don't care. They've had a lot of enemies in their time. Let them fight one enemy that doesn't care for a change.
3) Add a definition if FIELD_OFFSET wrapped in #ifndef. This is the least ugly option but would cause surprising results if one or the other was changed.
Personally, I think this looks the best. As far as which is likely to get accepted.. often you have to try first to find that out ;-) --Juan
On Tue, Apr 22, 2008 at 11:50:05PM +0900, Dmitry Timoshkov wrote:
"Erik de Castro Lopo" <mle+win(a)mega-nerd.com> wrote:
/* get pointer to object containing list element */ #define LIST_ENTRY(elem, type, field) \ - ((type *)((char *)(elem) - (unsigned int)(&((type *)0)->field))) + ((type *)((char *)(elem) - (unsigned long)(&((type *)0)->field)))
How about: ((type *)((char *)(elem) - ((char *)(&((type *)0)->field) - (char *)0))) David -- David Laight: david(a)l8s.co.uk
David Laight wrote:
On Tue, Apr 22, 2008 at 11:50:05PM +0900, Dmitry Timoshkov wrote:
"Erik de Castro Lopo" <mle+win(a)mega-nerd.com> wrote:
/* get pointer to object containing list element */ #define LIST_ENTRY(elem, type, field) \ - ((type *)((char *)(elem) - (unsigned int)(&((type *)0)->field))) + ((type *)((char *)(elem) - (unsigned long)(&((type *)0)->field)))
How about: ((type *)((char *)(elem) - ((char *)(&((type *)0)->field) - (char *)0)))
Much, much better, thank you. I don't know why I didn't see it myself. Cheers, Erik -- ----------------------------------------------------------------- Erik de Castro Lopo ----------------------------------------------------------------- "I saw `cout' being shifted "Hello world" times to the left and stopped right there." -- Steve Gonedes
participants (4)
-
David Laight -
Dmitry Timoshkov -
Erik de Castro Lopo -
Juan Lang