|
|
||||||
|
#1
|
|
|
|
|
Microsoft Visual C++ warning C4267 (the number is not a typo) can occur e.g.
when compiling Boost Spirit, or when doing std::size_t x = 0; std::cout << x; when compiled with 64-bit compatibility warnings enabled. One fix is to turn off conversion warnings, another _may be_ as follows -- I'm wondering whether someone could test this on a 64-bit machine, or have other comments: #include <iostream> // std::cout #include <ostream> // <<, std::endl #include <string> // std::string #include <vector> // std::vector template< typename T > struct Builtin { typedef T Type; }; template<> struct Builtin<int> { typedef int Type; }; template<> struct Builtin<unsigned int> { typedef unsigned int Type; }; template<> struct Builtin<long> { typedef long Type; }; template<> struct Builtin<unsigned long> { typedef unsigned long Type; }; #ifdef _MSC_VER template<> struct Builtin<__int64> { typedef __int64 Type; }; template<> struct Builtin<unsigned __int64> { typedef unsigned __int64 Type; }; #endif template< typename T > inline typename Builtin<T>::Type asBuiltin( T v ) { return static_cast<Builtin<T>::Type>( v ); } int main( int nArgs, char *szArgs[] ) { std::vector<std::string> const args( szArgs, szArgs + nArgs ); for( std::size_t i = 0; i < args.size(); ++i ) { std::cout << asBuiltin( i ) << ": [" << args.at( i ) << "]" << std::endl; } } |
|
|
|
#2
|
|
|
|
|
Alf P. Steinbach wrote:
> Microsoft Visual C++ warning C4267 (the number is not a typo) can occur e.g. > when compiling Boost Spirit, or when doing > > std::size_t x = 0; > std::cout << x; > > when compiled with 64-bit compatibility warnings enabled. > > One fix is to turn off conversion warnings, another _may be_ as follows -- > I'm wondering whether someone could test this on a 64-bit machine, or have > other comments: > That's an awful lot of code just to avoid a stupid warning. The code as originally written is well defined, clear, and unambiguous. The code as rewritten is impenetrable. Complain to Microsoft. |
|
|
| Similar Threads | |
| Using Boost.Spirit in production code I would be interested to know the opinion of this newsgroup on whether it is sensible using Boost.Spirit in production code. In a project I'm working on, I'm likely to need... |
|
| VC2005: incorrect warning C4267 Hi to all, the following sample triggers warning C4267, but that's incorrect, because the bitfields have the same size. Is there some subtle motivation? struct... |
|
| Incorrect compiler warning C4267 I'm running VS 2005, configured for 32 bit with 64 bit warnings on. This bit of code #include <vector> #include <list> std::vector<size_t> vs; std::list<unsigned int>... |
|
| warning C4267 and warning C4996 I am receiving two warnings in my code and can't figure out why. Will someone look at this and tell me what I have done wrong? #include <iostream> using... |
|
| warning C4267 and warning C4996 I am receiving two warnings in my code and can't figure out why. Will someone look at this and tell me what I have done wrong? #include <iostream> using... |
|
|
All times are GMT. The time now is 01:15 AM. | Privacy Policy
|