pragma

Should I still use #include guards AND #pragma once?

ぐ巨炮叔叔 提交于 2019-12-03 23:27:30
http://en.wikipedia.org/wiki/Pragma_once Should I still use include guards when all of these compilers support #pragma once ? A lot of responses on stack overflow say to use both for compatibility, but I'm not sure if that still rings true. What compilers today don't support #pragma once ? I am not sure if using both was just a recommendation before it became widley adopted, or if there are still very good reasons to use both methods. Any examples of when only using #pragma once will cause problems? It depends on how much portable your program is expected to be. As long as you are writing a

Can I enable/disable breaking on Exceptions programmatically?

徘徊边缘 提交于 2019-12-03 16:58:02
问题 I want to be able to break on Exceptions when debugging... like in Visual Studio 2008's Menu Debug/Exception Dialog, except my program has many valid exceptions before I get to the bit I wish to debug. So instead of manually enabling and disabling it using the dialog every time is it possible to do it automatically with a #pragma or some other method so it only happens in a specific piece of code? 回答1: The only way to do something close to this is by putting the DebuggerNonUserCodeAttribute

How to use GCC diagnostic pragma with C++ template functions?

不羁岁月 提交于 2019-12-03 16:22:27
I would like to use g++ and -Werror , so I have now to disable warnings for 3rd-party libraries I have no control of. The solution provided by http://gcc.gnu.org/onlinedocs/gcc/Diagnostic-Pragmas.html works very well, allowing simply to wrap the includes of 3rd party headers with pragmas. Unfortunately, that did no longer work for me in a certain setup where templates are involved. I created the following minimal example of where this approach did not work as expected: Source file main.cpp #pragma GCC diagnostic ignored "-Wunused-parameter" #include "hdr.hpp" #pragma GCC diagnostic error "

How to poison an identifier in VC++?

馋奶兔 提交于 2019-12-03 12:45:40
Function poisoning is very useful technique in C++. In general it refers to making a function unusable, e.g. if you want to ban the use of dynamic allocation in a program you could "poison" the malloc function so it can't be used. 'Poisoning' an identifier means that any reference to the identifier after the 'poisoning' is a hard compiler error For example (See live demo here ) #include <iostream> #include <cstdlib> #pragma GCC poison malloc int main() { int* p=(int*)malloc(sizeof(int)); // compiler error use of poisoned function malloc *p=3; std::cout<<*p<<'\n'; free(p); } I found this

Xcode - Using #pragma mark

不问归期 提交于 2019-12-03 10:58:15
问题 I'm pretty sure this isn't a duplicate. Do you use #pragma mark? I've seen multiple ways, which is correct? #pragma mark - #pragma mark === Actions === #pragma mark - #pragma mark - #pragma mark === Actions === #pragma mark - === Actions === #pragma mark Actions What is the way you do it? How do you suggest dividing it up? What do you normally name your sections, for say, a view controller? 回答1: There is no "Correct" way, it is annotation, so how you use it is a coding style issue. Having

Android database corrupt, but can open in SQLite Manager. Recoverable?

旧时模样 提交于 2019-12-03 10:38:35
In the latest two weeks, without releasing an update to my app, I have started getting a bunch of reports with corrupted databases. Below is the stacktrace. Android cannot open the database, and neither could the sqlite-manager program on my computer. However, the SQLite manager-addon to firefox could open it. After running the command "compact database", the database was fixed and I could open it in android. Is there any way I could do something like this within my app? The big problem is that I cannot even attempt to open the database, because newer versions of Android will immediately

Any way to group methods in Java/Eclipse?

☆樱花仙子☆ 提交于 2019-12-03 09:59:39
I would like to be able to group similar methods and have them appear in my Outline view in Eclipse. This makes navigating large swaths of code a little easier on the eye, and easier to find methods you need. In Objective-C there was a pragma mark command that you could set. Anything like that for java/eclipse? I use the Coffee Bytes plugin for code folding, specifically configuring it for folding code that has start and end tags. Although the plugin is not downloadable off the page listed on the Google Code page, it has been recompiled against Eclipse 3.5 and made available elsewhere ; the

How do people handle warning C4793: 'some_function' : function compiled as native?

梦想的初衷 提交于 2019-12-03 09:58:45
I'm using the OpenCV library and one of its header files, cxoperations.hpp, generates "warning C4793: 'anonymous namespace'::CV_XADD' : function compiled as native" , if my C++ project is compiled with CLR support. I can prevent the warning by surrounding the OpenCV header include like this: #pragma managed(push,off) #include <cv.h> #pragma managed(pop) But the project that actually uses OpenCV isn't compiled with CLR support, it's a native C++ static library. The project that does have CLR support, and generates this warning without the pragma statements, simply uses this static library. So I

Can I enable/disable breaking on Exceptions programatically?

泪湿孤枕 提交于 2019-12-03 06:07:35
I want to be able to break on Exceptions when debugging... like in Visual Studio 2008's Menu Debug/Exception Dialog, except my program has many valid exceptions before I get to the bit I wish to debug. So instead of manually enabling and disabling it using the dialog every time is it possible to do it automatically with a #pragma or some other method so it only happens in a specific piece of code? The only way to do something close to this is by putting the DebuggerNonUserCodeAttribute on your method. This will ensure any exceptions in the marked method will not cause a break on exception.

How do I show the value of a #define at compile time in gcc

泪湿孤枕 提交于 2019-12-03 04:52:32
问题 So far I've got as far as: #define ADEFINE "23" #pragma message ("ADEFINE" ADEFINE) Which works, but what if ADEFINE isn't a string? #define ADEFINE 23 #pragma message ("ADEFINE" ADEFINE) causes: warning: malformed ‘#pragma message’, ignored Ideally I'd like to be able to deal with any value, including undefined. 回答1: To display macros which aren't strings, stringify the macro: #define STRINGIFY(s) XSTRINGIFY(s) #define XSTRINGIFY(s) #s #define ADEFINE 23 #pragma message ("ADEFINE=" STRINGIFY