Re: [PATCH] man: explain role of unsigned long in casts from AS pointers.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, Mar 29, 2019 at 05:04:18PM -0700, Linus Torvalds wrote:
> On Fri, Mar 29, 2019 at 4:25 PM Luc Van Oostenryck
> <luc.vanoostenryck@xxxxxxxxx> wrote:
> >
> > Sparse will warn on casts removing the address space of a pointer
> > if the destination type is not unsigned long. But the special role
> > of 'unsigned long' is not explained in the man page.
> 
> You might as well call it "uintptr_t".
> 
> And yes, that is the same as "unsigned long" in all sane
> implementations, of course, and yes, the Linux kernel tends to prefer
> just using "unsigned long" rather than made-up abstract types
> internally.

Well, outside the kernel, uintptr_t is 'unsigned int' on ARM & i386
(and also riscv-32, MIPS with a 32-bit ABI, ppc32 & sparc32).

> But when explaining it outside of the Linux kernel context, I think
> "uintptr_t" might be a bit more appropriate (perhaps with an "aka
> unsigned long", since sparse itself internally also has the same "long
> and pointer are basically the same - it's the register size" model).
> 
> The logic is that an "uintptr_t" cast isn't really a pointer cast,
> it's a "get pointer value representation in an integer type" cast.
> Which is address-space independent, which can be used as an
> explanation of the logic.

Yes, uintptr_t should be ideal for this kind of casts, very clear
about the intention.

It should be easy enough to accept both 'uintptr_t' & 'unsigned long'.

-- Luc Van Oostenryck



[Index of Archives]     [Newbies FAQ]     [LKML]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Trinity Fuzzer Tool]

  Powered by Linux