pragma

Best workaround for compiler error C2158: make_public does not support native template types

元气小坏坏 提交于 2019-11-26 17:26:13
问题 I have two c++/cli dlls (i.e. compiled with /clr) where A.dll references B.dll. In assembly B, I have a method, GetMgdClassB, I'd like to call from assembly A. Here is the code in assembly B (B.cpp): namespace B { public class NativeClassB { public: NativeClassB(); // ... }; public ref class MgdClassB { public: static MgdClassB ^ GetMgdClassB(const std::vector<NativeClassB *> & vecNativeBs) { // ... vecNativeBs; return gcnew MgdClassB(); } }; } Notice that the method GetMgdClassB takes a std:

Disable single warning error

邮差的信 提交于 2019-11-26 13:04:41
Is there a way to disable just a single warning line in a cpp file with visual studio? For example, if I catch an exception and don't handle it, I get error 4101 (unreferenced local variable). Is there a way to ignore this just in that function, but otherwise report it in the compilation unit? At the moment, I put #pragma warning (disable : 4101) at the top of the file, but that obviously just turns it off for the whole unit. #pragma warning( push ) #pragma warning( disable : 4101) // Your function #pragma warning( pop ) If you only want to suppress a warning in a single line of code, you can

How to disable WAL journal mode

天大地大妈咪最大 提交于 2019-11-26 12:29:34
问题 https://developer.apple.com/library/ios/releasenotes/DataManagement/WhatsNew_CoreData_iOS/ I am having trouble in disabling journal mode. My code is: static NSManagedObjectContext *managedObjectContext(){ static NSManagedObjectContext *context = nil; if (context != nil) { return context; } NSString * const NSSQLitePragmasOption; NSSQLitePragmasOption : @{ @\"journal_mode\" : @\"DELETE\" }; @autoreleasepool { context = [[NSManagedObjectContext alloc] init]; NSPersistentStoreCoordinator

What does “#pragma comment” mean?

懵懂的女人 提交于 2019-11-26 11:47:56
问题 What does #pragma comment mean in the following? #pragma comment(lib, \"kernel32\") #pragma comment(lib, \"user32\") 回答1: #pragma comment is a compiler directive which indicates Visual C++ to leave a comment in the generated object file. The comment can then be read by the linker when it processes object files. #pragma comment(lib, libname) tells the linker to add the 'libname' library to the list of library dependencies, as if you had added it in the project properties at Linker->Input-

Why isn&#39;t C/C++&#39;s “#pragma once” an ISO standard?

。_饼干妹妹 提交于 2019-11-26 08:28:50
问题 I am currently working on a big project and maintaining all those include guards makes me crazy! Writing it by hand is frustrating waste of time. Although many editors can generate include guards this doesn\'t help much: Editor generates guard symbol based on a filename. The problem occurs when you have headers with the same filename in different directories. Both of them will get the same include guard. Including directory structure into the guard symbol would require some fancy approach

Is there a compiler hint for GCC to force branch prediction to always go a certain way?

巧了我就是萌 提交于 2019-11-26 07:56:14
问题 For the Intel architectures, is there a way to instruct the GCC compiler to generate code that always forces branch prediction a particular way in my code? Does the Intel hardware even support this? What about other compilers or hardwares? I would use this in C++ code where I know the case I wish to run fast and do not care about the slow down when the other branch needs to be taken even when it has recently taken that branch. for (;;) { if (normal) { // How to tell compiler to always branch

Use of #pragma in C

*爱你&永不变心* 提交于 2019-11-26 07:54:03
问题 What are some uses of #pragma in C, with examples? 回答1: #pragma is for compiler directives that are machine-specific or operating-system-specific, i.e. it tells the compiler to do something, set some option, take some action, override some default, etc. that may or may not apply to all machines and operating systems. See msdn for more info. 回答2: #pragma is used to do something implementation-specific in C, i.e. be pragmatic for the current context rather than ideologically dogmatic. The one I

Pragma in define macro

橙三吉。 提交于 2019-11-26 03:08:12
问题 Is there some way to embed pragma statement in macro with other statements? I am trying to achieve something like: #define DEFINE_DELETE_OBJECT(type) \\ void delete_ ## type_(int handle); \\ void delete_ ## type(int handle); \\ #pragma weak delete_ ## type_ = delete_ ## type I am okay with boost solutions (save for wave) if one exists. 回答1: If you're using c99 or c++0x there is the pragma operator, used as _Pragma("argument") which is equivalent to #pragma argument except it can be used in

Selectively disable GCC warnings for only part of a translation unit?

爷,独闯天下 提交于 2019-11-26 00:47:52
问题 What\'s the closest GCC equivalent to this MSVC preprocessor code? #pragma warning( push ) // Save the current warning state. #pragma warning( disable : 4723 ) // C4723: potential divide by 0 // Code which would generate warning 4723. #pragma warning( pop ) // Restore warnings to previous state. We have code in commonly included headers which we do not want to generate a specific warning. However we want files which include those headers to continue to generate that warning (if the project

How to disable GCC warnings for a few lines of code

雨燕双飞 提交于 2019-11-26 00:15:35
问题 In Visual C++, it\'s possible to use #pragma warning (disable: ...). Also I found that in GCC you can override per file compiler flags. How can I do this for \"next line\", or with push/pop semantics around areas of code using GCC? 回答1: It appears this can be done. I'm unable to determine the version of GCC that it was added, but it was sometime before June 2010. Here's an example: #pragma GCC diagnostic error "-Wuninitialized" foo(a); /* error is given for this one */ #pragma GCC diagnostic