Huge thanks to our Platinum Members Endace and LiveAction,
and our Silver Member Veeam, for supporting the Wireshark Foundation and project.

Wireshark-dev: Re: [Wireshark-dev] MSVC 2015 failures

From: Guy Harris <guy@xxxxxxxxxxxx>
Date: Fri, 5 Jun 2015 12:22:10 -0700
On Jun 5, 2015, at 3:50 AM, Anders Broman <anders.broman@xxxxxxxxxxxx> wrote:
 
> in_cksum.c(92): error C2220: warning treated as error - no 'object' file generated
> in_cksum.c(92): warning C4311: 'type cast': pointer truncation from 'const guint16 *' to 'unsigned long'

This is trying to do 2-byte operations with word loads/stores/arithmetic instructions, but to do it safely, so that we don't do those with unaligned pointers.  It's testing the low-order bit of the pointer.

On ILP32 platforms, such as 32-bit UN*Xes and 32-bit Windows, an int, a long, and a pointer are all 32 bits, so you can just cast a pointer to an int or a long.

On LP64 platforms, such as all the 64-bit UN*Xes we support, a long and a pointer are both 64 bits, so you can just cast a pointer to a long.

On LLP64 platforms, such as 64-bit Windows, an int and a long are both 32 bits, and a long long and a pointer are both 64 bits, so you can't just cast a pointer to a long without throwing away bits.  Those bits don't actually *matter* in this case, but the compiler still warns.

C99 has an intptr_t type, but C90 doesn't.  MSVC has it at least as far back as Visual Studio .NET 2003:

	https://msdn.microsoft.com/en-us/library/323b6b3k(v=vs.71).aspx

I don't know whether any UN*X platforms we support don't have it; I suspect most if not all of them have adopted it.

Alternatively, GLib 2.18 and later have gintptr, although configure.ac currently only requires 2.16 or later.