compiler-specific

Does using __declspec(novtable) on abstract base classes affect RTTI in any way?

て烟熏妆下的殇ゞ 提交于 2020-01-22 17:45:29
问题 Or, are there any other known negative affects of employing __declspec(novtable)? I can't seem to find references to any issues. 回答1: MSCV uses one vptr per object and one vtbl per class to implement OO mechanism such as RTTI and virtual functions. So RTTI and virtual functions will work fine if and only if the vptr has been set correctly. struct __declspec(novtable) B { virtual void f() = 0; }; struct D1 : B { D1() { } // after the construction of D1, vptr will be set to vtbl of D1. }; D1 d1

Why is MSVC compiler wierdly slower than gcc on Linux and Xcode C++ compiler on Mac

吃可爱长大的小学妹 提交于 2019-12-23 03:49:35
问题 I couldn't figure out why the execution time for the following code snippet varies significantly on Windows(MSVC++)Virtual machine, Linux(GCC)virtual machine and Mac(xCode) physical machine. #include <iostream> #include <ctime> #include <ratio> #include <chrono> using namespace std; using namespace std::chrono; int main() { const int TIMES = 100; const int STARS = 1000; steady_clock::time_point t1;// = steady_clock::now(); steady_clock::time_point t2;// = steady_clock::now(); int

Why is MSVC compiler wierdly slower than gcc on Linux and Xcode C++ compiler on Mac

送分小仙女□ 提交于 2019-12-08 08:38:31
I couldn't figure out why the execution time for the following code snippet varies significantly on Windows(MSVC++)Virtual machine, Linux(GCC)virtual machine and Mac(xCode) physical machine. #include <iostream> #include <ctime> #include <ratio> #include <chrono> using namespace std; using namespace std::chrono; int main() { const int TIMES = 100; const int STARS = 1000; steady_clock::time_point t1;// = steady_clock::now(); steady_clock::time_point t2;// = steady_clock::now(); int totalCountMicro = 0; int totalCountMilli = 0; for(int i = 0; i < TIMES; i++) { t1 = steady_clock::now(); for (int j

C++11 feature checking

核能气质少年 提交于 2019-11-29 04:28:40
How do I check for presence of individual C++0x/C++11 language features? I know Clang has a nice system for this. What about GCC, Visual Studio or Boost? I guess one way to do it is to detect the compiler version and relate that to the features introduced in that version. But that is cumbersome. Has someone already done that? mirk boost config comes with a script to check for some but not all C++11 features. It generates a config-file with macros for each feature. Your build-tool may be able to help with this. CMake has the try_compile command which allows you to test whether a code sample

Write a program that will print “C” if compiled as an (ANSI) C program, and “C++” if compiled as a C++ program

别来无恙 提交于 2019-11-28 06:57:17
Taken from http://www.ocf.berkeley.edu/~wwu/riddles/cs.shtml It looks very compiler specific to me. Don't know where to look for? Simple enough. #include <stdio.h> int main(int argc, char ** argv) { #ifdef __cplusplus printf("C++\n"); #else printf("C\n"); #endif return 0; } Or is there a requirement to do this without the official standard? We had to do a similar assignment at school. We were not allowed to use preprocessor (except for #include of course). The following code uses the fact that in C, type names and structure names form separate namespaces whereas in C++ they don't. #include

C++11 feature checking

做~自己de王妃 提交于 2019-11-27 18:22:04
问题 How do I check for presence of individual C++0x/C++11 language features? I know Clang has a nice system for this. What about GCC, Visual Studio or Boost? I guess one way to do it is to detect the compiler version and relate that to the features introduced in that version. But that is cumbersome. Has someone already done that? 回答1: boost config comes with a script to check for some but not all C++11 features. It generates a config-file with macros for each feature. 回答2: Your build-tool may be

Write a program that will print “C” if compiled as an (ANSI) C program, and “C++” if compiled as a C++ program

こ雲淡風輕ζ 提交于 2019-11-27 01:42:31
问题 Taken from http://www.ocf.berkeley.edu/~wwu/riddles/cs.shtml It looks very compiler specific to me. Don't know where to look for? 回答1: Simple enough. #include <stdio.h> int main(int argc, char ** argv) { #ifdef __cplusplus printf("C++\n"); #else printf("C\n"); #endif return 0; } Or is there a requirement to do this without the official standard? 回答2: We had to do a similar assignment at school. We were not allowed to use preprocessor (except for #include of course). The following code uses