Re: type safe lists (was Re: PATCH: type safe(r) list_entry repacement: generic_out_cast)

From: Anton Altaparmakov (aia21@cantab.net)
Date: Wed Jul 24 2002 - 03:24:02 EST


At 08:39 24/07/02, Martin Brulisauer wrote:
>On 24 Jul 2002, at 2:07, Joshua MacDonald wrote:
>I have one additional comment to the current implementation:
> >
> > #define TS_LINK_TO_ITEM(ITEM_TYPE,LINK_NAME,LINK) \
> > ((ITEM_TYPE *)((char *)(LINK)-(unsigned long)(&((ITEM_TYPE
> *)0)->LINK_NAME)))
>
>As long as your pointers are 32bit this seems to be ok. But on
>64bit implementations pointers are not (unsigned long) so this cast
>seems to be wrong.

On 64-bit architectures unsigned long is 64-bits so there is no problem. In
fact the core kernel code _requires_ that unsigned long is large enough to
fully contain the contents of a pointer. (E.g. look at linux/mm/memory.c,
well really linux/mm/*.c for the tip of the iceberg).

Of course if one wanted to be really pedantic, one could replace the
unsigned long typecasts with ptrdiff_t. But you would have to go through a
_lot_ of code where the kernel currently casts between unsigned long and
(mostly) void * to do this in a one off conversion.

Best regards,

         Anton

-- 
   "I've not lost my mind. It's backed up on tape somewhere." - Unknown
-- 
Anton Altaparmakov <aia21 at cantab.net> (replace at with @)
Linux NTFS Maintainer / IRC: #ntfs on irc.openprojects.net
WWW: http://linux-ntfs.sf.net/ & http://www-stu.christs.cam.ac.uk/~aia21/

- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/



This archive was generated by hypermail 2b29 : Tue Jul 30 2002 - 14:00:15 EST