Re: [PATCH] block-sha1/sha1.c: silence compiler complaints by casting void* to uintptr_t
- From
Linus Torvalds <torvalds@linux-foundation.org>
- Date
- Aug 15, 2009, 00:19 UTC
- Message-ID
- <alpine.LFD.2.01.0908141714040.3162@localhost.localdomain>
- In-Reply-To
- <alpine.DEB.1.00.0908150207270.8306@pacific.mpi-cbg.de>
On Sat, 15 Aug 2009, Johannes Schindelin wrote:
> > I am confused. Is sizeof(*(uintptr_t)NULL) not larger than 1
You can't do that. "uintptr_t" isn't actually a pointer. It's just a unsigned integer value large enough to contain a pointer.
So it's _not_ a "pointer to uint". It's "uint that can contain all the bits of a poitner".
> and as a consequence ((uintptr_t)p)+1 not different from ((void *)p)+1?
No, they're the same.
That said, I suspect it might as well be cast to "const char *", and then hopefully you only need one cast.
So maybe it could be written as
data = (const char *) data + len;
instead, and avoid the second cast (because the assignment should be ok, since it's assigning back to a "const void *").
Linus