Sign in to follow this  

How do I get rid of this compiler warning?

This topic is 4197 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have 2 warnings that are in the file xlocnum, here is what the compiler says:
c:\program files\microsoft visual studio 8\vc\include\xlocnum(590) : warning C4312: 'type cast' : conversion from 'uintptr_t' to 'void *' of greater size
        c:\program files\microsoft visual studio 8\vc\include\xlocnum(566) : while compiling class template member function 'std::istreambuf_iterator<_Elem,_Traits> std::num_get<_Elem,_InIt>::do_get(_InIt,_InIt,std::ios_base &,std::ios_base::iostate &,void *&) const'
        with
        [
            _Elem=char,
            _Traits=std::char_traits<char>,
            _InIt=std::istreambuf_iterator<char,std::char_traits<char>>
        ]
        c:\program files\microsoft visual studio 8\vc\include\xlocnum(1365) : see reference to class template instantiation 'std::num_get<_Elem,_InIt>' being compiled
        with
        [
            _Elem=char,
            _InIt=std::istreambuf_iterator<char,std::char_traits<char>>
        ]

and the other one is:
c:\program files\microsoft visual studio 8\vc\include\xlocnum(590) : warning C4312: 'type cast' : conversion from 'uintptr_t' to 'void *' of greater size
        c:\program files\microsoft visual studio 8\vc\include\xlocnum(566) : while compiling class template member function 'std::istreambuf_iterator<_Elem,_Traits> std::num_get<_Elem,_InIt>::do_get(_InIt,_InIt,std::ios_base &,std::ios_base::iostate &,void *&) const'
        with
        [
            _Elem=wchar_t,
            _Traits=std::char_traits<wchar_t>,
            _InIt=std::istreambuf_iterator<wchar_t,std::char_traits<wchar_t>>
        ]
        c:\program files\microsoft visual studio 8\vc\include\xlocnum(1371) : see reference to class template instantiation 'std::num_get<_Elem,_InIt>' being compiled
        with
        [
            _Elem=wchar_t,
            _InIt=std::istreambuf_iterator<wchar_t,std::char_traits<wchar_t>>
        ]

Edit: Oops forgot to mention this is C++ and I have Visual Studio 2005 EE

Share this post


Link to post
Share on other sites
If you're completely sure that the warning should just be removed (it seems like it's a problem in the SC++L), then you can do this

#pragma warning(push)
#pragma warning(disable : 4312)
#include <theheader>
#pragma warning(pop)

Where theheader is theheader creating the warnings.

Share this post


Link to post
Share on other sites
Are you compiling for some kind of hybrid 32 bit/64 bit universe?

I mean, this warning looks strange:
conversion from 'uintptr_t' to 'void *' of greater size


These, naively, shouldn't be different sizes...

Does
int x[sizeof(void*) - sizeof(uintptr_t)];

compile?

Share this post


Link to post
Share on other sites
I assume uint_ptr_t is defined in the same way as UINT_PTR, ie:
#if defined(_WIN64)
typedef unsigned __int64 UINT_PTR;
#else
typedef unsigned int UINT_PTR;
#endif

Thus, when building on a 32-bit system, uint_ptr_t and void * are both 32 bits.

I'm guessing that the OP has "Detect 64-bit portability issues" enabled in his build options. This option will cause the system to consider void * as 64 bits, but since _WIN64 is not defined (we are building for a 32-bit system), uint_ptr_t is still 32-bits. Thus in this case, void * is of greater size than uint_ptr_t.

The simple way to remove the warnings is to disable "Detect 64-bit portability issues".

In summary, "Detect 64-bit portability issues" finds issues where none exist. IMO, you're best off turning this option off and finding 64-bit portability issues by compiling your code on a 64-bit compiler.

Share this post


Link to post
Share on other sites
Ok, I think I understand now. Do you think I accidentally put that feature on when creating the project or is that the default option? How could I turn off that detect 64 portability option? Is it somewhere in project options?

Share this post


Link to post
Share on other sites
Quote:
Original post by eektor
Do you think I accidentally put that feature on when creating the project or is that the default option?


It seems to be the default.

Quote:
How could I turn off that detect 64 portability option? Is it somewhere in project options?


On VS 2003 (and I expect 2005 to be the same), it's Project-><Project name> properties->C/C++->General->Detect 64-bit portability issues.

Share this post


Link to post
Share on other sites
Quote:
Original post by bakery2k1
I assume uint_ptr_t is defined in the same way as UINT_PTR, ie:
#if defined(_WIN64)
typedef unsigned __int64 UINT_PTR;
#else
typedef unsigned int UINT_PTR;
#endif

Thus, when building on a 32-bit system, uint_ptr_t and void * are both 32 bits.


Oh god. Whoever wrote those typedefs is a git. (no, not you bakery2k1).

[Edited by - NotAYakk on June 15, 2006 2:55:44 PM]

Share this post


Link to post
Share on other sites

This topic is 4197 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this