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

Anton Altaparmakov (aia21@cantab.net)
Wed, 24 Jul 2002 09:24:02 +0100


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/