Re: [PATCH] block-sha1/sha1.c: silence compiler complaints by casting void* to uintptr_t
- From
Brandon Casey <casey@nrlssc.navy.mil>
- Date
- Aug 15, 2009, 00:52 UTC
- Message-ID
- <qZXfoQ5Gp5jKnRfKM6ee07YVX-hyS2HsJmQwAYdPVHw92cOuUcufJA@cipher.nrlssc.navy.mil>
- In-Reply-To
- <alpine.DEB.1.00.0908150207270.8306@pacific.mpi-cbg.de>
Johannes Schindelin wrote:
Show 9 quoted lines
> Hi, > > On Fri, 14 Aug 2009, Brandon Casey wrote: > >> Some compilers produce errors when arithmetic is attempted on pointers to >> void. So cast to uintptr_t when performing arithmetic on void pointers. > > I am confused. Is sizeof(*(uintptr_t)NULL) not larger than 1, and as a > consequence ((uintptr_t)p)+1 not different from ((void *)p)+1?
If you try this:
printf("NULL + 1: %u\n", (void*)NULL + 1);the MIPSpro compiler complains like:
The expression must be a pointer to a complete object type.
printf("NULL + 1: %u\n", (void*)NULL + 1);
^1 error detected in the compilation of "test.c".
Compilers other than gcc at least issue a warning, if they do not also fail.
-brandon