visual-c++-2010

How do I exclude library headers from my Visual Studio static code analysis?

二次信任 提交于 2019-12-05 02:44:33
I have setup buildbot to compile my Qt/C++ application with the /analyze flag. However the analysis is also delving into the qt headers which I don't care about: c:\qt\qt-everywhere-opensource-src-4.8.1\src\corelib\tools\qvector.h(547) : warning C6011: Dereferencing NULL pointer 'x.p': Lines: 474, 475, 476, 477, 478, 480, 491, 493, 497, 498, 499, 500, 503, 504, 518, 519, 520, 521, 522, 525, 545, 547 Whats the best way to exclude these files en mass? (Please note I am not using the IDE, I am looking for a command line, switch or code change) James McNellis You can disable all code analysis

Warning C4800: 'int' : forcing value to bool 'true' or 'false' (performance warning)

余生长醉 提交于 2019-12-04 22:16:20
I have this problem in my code: bool CBase::isNumber() { return (id & MID_NUMBER); } bool CBase::isVar() { return (id & MID_VARIABLE); } bool CBase::isSymbol() { return (id & MID_SYMBOL); } FYI: Casts won't hide the warning by design . Something like return (id & MID_NUMBER) != 0; should clearly state "I want to check whether this value is zero or not" and let the compiler be happy Use the !! idiom eg bool CBase::isNumber() { return !!(id & MID_NUMBER); } Where's the declaration of id and MID_NUMBER? Are you sure they are not windef-style BOOLs rather than (lowercase) bool's? BOOL's have been

Copy constructor is not called for copy-initialization or optimized?

匆匆过客 提交于 2019-12-04 05:20:19
问题 If copy constructor is made private then in Case 1: No error, the compiler doesn't care if the copy constructor was defined in class. Case 2: Error, copy constructor is private and when it is made public , it is elided. Does it directly optimizes the copy without being noticing that if the constructor was made private ? #include <string> using std::string; class T { string s; T(const T &obj):s(obj.s){} public: T(const string &str):s(str){} }; int main() { T a = ("Copy Initialization"); //Case

How can I get an intrinsic for the exp() function in x64 code?

我与影子孤独终老i 提交于 2019-12-04 02:35:46
I have the following code and am expecting the intrinsic version of the exp() function to be used. Unfortunately, it is not in an x64 build, making it slower than a similar Win32 (i.e., 32-bit build): #include "stdafx.h" #include <cmath> #include <intrin.h> #include <iostream> int main() { const int NUM_ITERATIONS=10000000; double expNum=0.00001; double result=0.0; for (double i=0;i<NUM_ITERATIONS;++i) { result+=exp(expNum); // <-- The code of interest is here expNum+=0.00001; } // To prevent the above from getting optimized out... std::cout << result << '\n'; } I am using the following

Dependent Non-Type Template Parameters

本小妞迷上赌 提交于 2019-12-04 02:02:59
Consider the following class: class Foo { enum Flags {Bar, Baz, Bax}; template<Flags, class = void> struct Internal; template<class unused> struct Internal<Bar, unused> {/* ... */}; template<class unused> struct Internal<Baz, unused> {/* ... */}; template<class unused> struct Internal<Bax, unused> {/* ... */}; }; The class outline above compiles and functions as expected when tested on VC++ 2010 and Comeau C++. However, when Foo is made into a template itself, the above snippet breaks under VC++ 2010. For example, the following snippet: template<class> class Foo { // Same contents as the

initializer_list not working in VC10

 ̄綄美尐妖づ 提交于 2019-12-04 00:49:16
i wrote this program in VC++ 2010: class class1 { public: class1 (initializer_list<int> a){}; int foo; float Bar; }; void main() { class1 c = {2,3}; getchar(); } but i get this errors when i compile project: Error 1 error C2552: 'c' : non-aggregates cannot be initialized with initializer list c:\users\pswin\documents\visual studio 2010\projects\test_c++0x\test_c++0x\main.cpp 27 and 2 IntelliSense: initialization with '{...}' is not allowed for object of type "class1" c:\users\pswin\documents\visual studio 2010\projects\test_c++0x\test_c++0x\main.cpp 27 what is the problem? Georg Fritzsche It

Closure and nested lambdas in C++0x

我只是一个虾纸丫 提交于 2019-12-03 23:58:18
Using C++0x, how do I capture a variable when I have a lambda within a lambda? For example: std::vector<int> c1; int v = 10; <--- I want to capture this variable std::for_each( c1.begin(), c1.end(), [v](int num) <--- This is fine... { std::vector<int> c2; std::for_each( c2.begin(), c2.end(), [v](int num) <--- error on this line, how do I recapture v? { // Do something }); }); Puppy std::for_each( c1.begin(), c1.end(), [&](int num) { std::vector<int> c2; int& v_ = v; std::for_each( c2.begin(), c2.end(), [&](int num) { v_ = num; } ); } ); Not especially clean, but it does work. The best I could

How do you use the pause assembly instruction in 64-bit C++ code?

可紊 提交于 2019-12-03 16:34:14
问题 Since inlined assembly is not supported by VC++ 2010 in 64-bit code, how do I get a pause x86-64 instruction into my code? There does not appear to be an intrinsic for this like there is for many other common assembly instructions (e.g., __rdtsc() , __cpuid() , etc...). On the why side, I want the instruction to help with a busy wait use case, so that the (hyperthreaded) CPU is available to other threads running on said CPU (See: Performance Insights at intel.com). The pause instruction is

VC++ 10 MFC: What is the correct way to do localization

巧了我就是萌 提交于 2019-12-03 12:55:45
问题 I am a .NET guy who is having to do some work on an MFC app. The app is a VS2008 MFC executable which I have converted to VS2010. The original developers did localisation by specifying the name of a .txt file with key value pairs in it on the applications command line. Installed shortcuts to the executable specify a different .txt file depending on which country the app is being installed in. This of course does not work if you just run the .exe directly. This seems like a weird way to do

How do you use the pause assembly instruction in 64-bit C++ code?

时间秒杀一切 提交于 2019-12-03 06:41:49
Since inlined assembly is not supported by VC++ 2010 in 64-bit code, how do I get a pause x86-64 instruction into my code? There does not appear to be an intrinsic for this like there is for many other common assembly instructions (e.g., __rdtsc() , __cpuid() , etc...). On the why side, I want the instruction to help with a busy wait use case, so that the (hyperthreaded) CPU is available to other threads running on said CPU (See: Performance Insights at intel.com). The pause instruction is very helpful for this use case as well as spin-lock implementations, I can't understand why MS did not