pragma

Why and when do we need to use #pragma [closed]

那年仲夏 提交于 2019-12-06 05:58:45
Closed . This question needs to be more focused . It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post . Closed 6 years ago . I was learning a winsock client server program and came up through #pragma comment(lib,"ws2_32.lib") . Understood its need here. But what are the other instances I can use it and why do I need to use it? dhein #pragma 's are implementation defined compiler commands. That means, each compiler could treat or support pragmas in a different way. They are used for example for

Are there any preprocessor directives that control loop unrolling?

微笑、不失礼 提交于 2019-12-05 22:21:43
问题 Furthermore, how does the compiler determine the extent to unroll a loop, assuming all operations in the loop are completely independent of other iterations. 回答1: For MSVC there is only a vector independence hint: http://msdn.microsoft.com/en-us/library/hh923901.aspx #pragma loop( ivdep ) For many other compilers, like Intel/ibm, there a several pragma hints for optimizing a loop: #pragma unroll #pragma loop count N #pragma ivdep There is a thread with MSVC++ people about unroll heuristic:

Pragma to Hide Warning: the field used in the where condition may contain null values

二次信任 提交于 2019-12-05 21:40:26
I'm looking for a pragma I can use to hide the compiler warning generated when a field used in the WHERE condition of a select may contain NULL values in the database. Having read SAP note 1088403, I am aware of the possible issues here but I cannot apply the solutions suggested there since I'm using a range, not a single value in the WHERE clause. In either case this is legacy code that was never found to be defective (as far as we know) and will be replaced before long. However while I'm rewriting other sections of the program, I'd like to disable this warning with a pragma . Could anyone

#pragma init and #pragma fini using gcc compiler on linux

大兔子大兔子 提交于 2019-12-05 16:40:10
问题 I would like to build some code which calls some code on loadup of the shared library. I thought i would do it like this: #pragma init(my_init) static void my_init () { //do-something } int add (int a,int b) { return a+b; } So when i build that code with gcc -fPIC -g -c -Wall tt.c It returns gcc -fPIC -g -c -Wall tt.c tt.c:2: warning: ignoring #pragma init tt.c:4: warning: ‘my_init’ defined but not used So its ignoring my #pragmas. I tried this in real code and my code aborted because a

pragma STDC FENV_ACCESS ON is not supported

谁说我不能喝 提交于 2019-12-05 13:46:41
I tried to slightly modify the example from the article : #include <iostream> #include <cfenv> #pragma STDC FENV_ACCESS ON int main() { std::feclearexcept(FE_ALL_EXCEPT); //int r = std::feraiseexcept(FE_UNDERFLOW | FE_DIVBYZERO); double x = 1.0; double y = 0.0; double result{}; asm volatile ("fldl %1\n" "fdivl %2\n" : "=%t"(result) : "m"(x), "m"(y) : "memory"); std::cout << result << std::endl; int e = std::fetestexcept(FE_ALL_EXCEPT); if (e & FE_DIVBYZERO) { std::cout << "division by zero\n"; } if (e & FE_INEXACT) { std::cout << "inexact\n"; } if (e & FE_INVALID) { std::cout << "invalid\n"; }

How portable is code with #pragma optimize?

隐身守侯 提交于 2019-12-05 10:45:14
How portable is code that uses #pragma optimize ? Do most compilers support it and how complete is the support for this #pragma ? #pragma is the sanctioned and portable way for compilers to add non-sanctioned and non-portable language extensions * . Basically, you never know for sure, and at least one major C++ compiler (g++) does not support this pragma as is. * : From the C++ standard (N3242): 16.6 Pragma directive [cpp.pragma] A preprocessing directive of the form # pragma pp-tokens opt new-line causes the implementation to behave in an implementation-defined manner. The behavior might

How do I implement a macro that creates a quoted string for _Pragma?

时光总嘲笑我的痴心妄想 提交于 2019-12-05 07:57:52
I want to have a macro that's invoked like this: GCC_WARNING(-Wuninitialized) which expands to code like this: _Pragma("GCC diagnostic ignored \"-Wuninitialized\"") I'm not having luck getting this to work, as the usual tricks of preprocessor joins and stringifying don't seem to apply or I don't know how to apply them here. With the little help of preprocessor magic: #define HELPER0(x) #x #define HELPER1(x) HELPER0(GCC diagnostic ignored x) #define HELPER2(y) HELPER1(#y) #define GCC_WARNING(x) _Pragma(HELPER2(x)) GCC_WARNING(-Wuninitialized) Would it also be acceptable if the macro argument is

Is it possible to disable compiler warning C4503?

◇◆丶佛笑我妖孽 提交于 2019-12-05 03:44:52
The following code does NOT suppress ANY C4503 compiler warnings, but it does suppress C4244 warnings. #pragma warning(push) #pragma warning(disable:4503) #pragma warning(disable:4244) #include <map> #include <string> int main(int argc, char *argv[]) { class Field; typedef std::map<std::string, Field * > Screen; typedef std::map<std::string, Screen> WebApp; typedef std::map<std::string, WebApp> WebAppTest; typedef std::map<std::string, WebAppTest> Hello; Hello MyWAT; // The C4503 error is NOT suppressed int a; a = 5.0f; // The C4244 error is suppressed } #pragma warning(pop) Please

What is the use of “#pragma section <XYZ>” in C?

杀马特。学长 韩版系。学妹 提交于 2019-12-05 01:39:44
What is the use of "#pragma section <XYZ>" in C ? I have come across C code file where the following kind was used:- #define XYZ "ITEM 26.G03" #pragma section <XYZ> where XYZ is: #define XYZ "ITEM 26.G03" I need some explaination on the use of "#pragma section" TOC The #pragma directive is an implementation specific directive it is a standard way to provide additional information to the compiler. This directive has the following form: #pragma name If the preprocessor recognizes the specified "name", it performs whatever action they stand for, or passes information on to the compiler. If "name"

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

拟墨画扇 提交于 2019-12-05 01:32:03
问题 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