Dave's Brain

Browse - Programming Tips - How can I avoid MS VC++ warning C4311:

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

Add a comment

Sign in to add a comment
Copyright © 2008-2018, 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.