Dave's Brain

Browse - programming tips - avoid vc warning c4311 pointer truncation from pointer to long

Date: 2010apr8
Language: C/C++
Product: MSVC++

Q.  How can I avoid MS VC++ warning C4311:

	warning C4311: 'type cast' : pointer truncation from '<pointer>' to 'LONG'

A.  You can disable the warning temporarily like this:

	#pragma warning(push)
	#pragma warning(disable: 4311)
		LONG my_long = (LONG) my_pointer;
	#pragma warning(pop)

Or you can use a builtin inline function to do the conversion (nicer):

		LONG my_long = PtrToLong(my_pointer);

More of these here:
http://msdn.microsoft.com/en-us/library/aa384267.aspx
What this info useful to you? You can donate to say thanks

Add a comment

Sign in to add a comment
Copyright © 2008-2012, dave - Code samples on Dave's Brain is licensed under the Creative Commons Attribution 2.5 License. However other material, including English text has all rights reserved.
Advertisements: