How do I get rid of this compiler warning?

Started by
9 comments, last by eektor 17 years, 10 months ago
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
Advertisement
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.
http://msdn2.microsoft.com/en-us/library/h97f4b9y.aspx
Well, I'm wondering if I did anything wrong. I didn't write that file, that came with the compiler. I don't even know why I even use that file.
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?
I'm just a beginner working in SDL and C++.

The only files I included were iostream, sstream, string, cmath, SDL/SDL.h, SDL/SDL_image.h, and SDL/SDL_ttf.h
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.
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?
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.
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]

This topic is closed to new replies.

Advertisement