error LNK2005: xxx already defined in MSVCRT.lib(MSVCR100.dll) C:\something\LIBCMT.lib(setlocal.obj)

You are mixing code that was compiled with /MD (use DLL version of CRT) with code that was compiled with /MT (use static CRT library). That cannot work, all source code files must be compiled with the same setting. Given that you use libraries that were pre-compiled with /MD, almost always the correct setting, you … Read more

How can I insert element into beginning of vector?

Use the std::vector::insert function accepting an iterator to the first element as a target position (iterator before which to insert the element): #include <vector> int main() { std::vector<int> v{ 1, 2, 3, 4, 5 }; v.insert(v.begin(), 6); } Alternatively, append the element and perform the rotation to the right: #include <vector> #include <algorithm> int main() … Read more

Double cast to unsigned int on Win32 is truncating to 2,147,483,648

A compiler bug… From assembly provided by @anastaciu, the direct cast code calls __ftol2_sse, which seems to convert the number to a signed long. The routine name is ftol2_sse because this is an sse-enabled machine – but the float is in a x87 floating point register. ; Line 17 call _getDouble call __ftol2_sse push eax … Read more

Is using #pragma warning push/pop the right way to temporarily alter warning level?

This will work with multiple compilers (and different versions of compilers). Header “push” #if defined(__clang__) # pragma clang diagnostic push #endif #if defined(_MSC_VER) # pragma warning(push) #endif #if defined(YOUR_FAVORITE_COMPILER) # pragma your compiler push warning #endif Header “pop” #if defined(__clang__) # pragma clang diagnostic pop #endif #if defined(_MSC_VER) # pragma warning(pop) #endif Some warning #if … Read more

Visual Studio 2010’s strange “warning LNK4042”

I had a similar problem with linker warning LNK4042: object specified more than once; extras ignored. In my case Visual Studio was trying to compile both header and source files with the same name – MyClass.h and MyClass.cpp. It happened because I renamed .cpp file to .h and Visual Studio got confused. I noticed the … Read more