By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,302 Members | 1,453 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,302 IT Pros & Developers. It's quick & easy.

A code fix for MSVC warning C4267 (64-bit compatibility warning, e.g. Boost Spirit)

P: n/a
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;
}
}

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Jul 23 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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.

--

Pete Becker
Dinkumware, Ltd. (http://www.dinkumware.com)
Jul 23 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.