pragma

How can I use #pragma message() so that the message points to the file(lineno)?

左心房为你撑大大i 提交于 2020-02-26 04:42:36
问题 In order to add 'todo' items into my code, I want to put a message in the compiler output. I would like it to look like this: c:/temp/main.cpp(104): TODO - add code to implement this in order to make use of the Visual Studio build output functionality to navigate to the respective line by double-clicking it. But the __LINE__ macro seems to expand to an int , which disallows writing #pragma message( __FILE__ "("__LINE__"): ..." ) Would there be another way? 回答1: Here is one that allows you to

How portable is code with #pragma optimize?

。_饼干妹妹 提交于 2020-01-23 07:20:12
问题 How portable is code that uses #pragma optimize? Do most compilers support it and how complete is the support for this #pragma ? 回答1: #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

Use #pragma pack with #define on Borland C++

≡放荡痞女 提交于 2020-01-23 01:02:45
问题 I am trying to pack some structs with Borland C++Builder (XE6) (in the future: bcc). I am using a library which uses the following construct to create structs: #ifdef _MSC_VER #define PACKED_BEGIN __pragma(pack(push, 1)) #define PACKED #define PACKED_END __pragma(pack(pop)) #elif defined(__GNUC__) #define PACKED_BEGIN #define PACKED __attribute__((__packed__)) #define PACKED_END #endif PACKED_BEGIN struct PACKED { short someSampleShort; char sampleByte; int sampleInteger; } structType_t;

Pragmas in python

跟風遠走 提交于 2020-01-22 10:35:07
问题 I'm reading bottle.py source code. It's a web framework, with only 3000+ lines python code. So cool. I found some code like this: class ServerAdapter(object): quiet = False def __init__(self, host='127.0.0.1', port=8080, **config): self.options = config self.host = host self.port = int(port) def run(self, handler): # pragma: no cover pass ... What does the # pragma: no cover mean? I can't find any introduce about the pragma syntax in the python documentations. 回答1: It is apparenly related to

#pragma once and #include issues

风格不统一 提交于 2020-01-17 10:20:17
问题 I had an issue of circular references (i.e. A.h and B.h #including each other) and some people advised me to use #pragma once to prevent that. However, this solution appears to be not working still. What's happening is that class A no longer becomes recognized in any file other than A.h (not even in A.cpp) and the same happens for class B. Let me show you the code: A.h #pragma once #include "B.h" class A { public: B* b; }; B.h #pragma once #include "A.h" class B { public: A* a; }; A.cpp

Why does the compiler ignore OpenMP pragmas?

百般思念 提交于 2020-01-16 06:58:06
问题 In the following C code I am using OpenMP in a nested loop. Since race condition occurs, I want to perform atomic operations at the end: double mysumallatomic() { double S2 = 0.; #pragma omp parallel for shared(S2) for(int a=0; a<128; a++){ for(int b=0; b<128;b++){ double myterm = (double)a*b; #pragma omp atomic S2 += myterm; } } return S2; } The thing is that #pragma omp atomic has no effect on the program behaviour, even if I remove it, nothing happens. Even if I change it to #pragma oh_my

Why does the compiler ignore OpenMP pragmas?

落爺英雄遲暮 提交于 2020-01-16 06:57:13
问题 In the following C code I am using OpenMP in a nested loop. Since race condition occurs, I want to perform atomic operations at the end: double mysumallatomic() { double S2 = 0.; #pragma omp parallel for shared(S2) for(int a=0; a<128; a++){ for(int b=0; b<128;b++){ double myterm = (double)a*b; #pragma omp atomic S2 += myterm; } } return S2; } The thing is that #pragma omp atomic has no effect on the program behaviour, even if I remove it, nothing happens. Even if I change it to #pragma oh_my

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

女生的网名这么多〃 提交于 2020-01-13 09:36:49
问题 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. 回答1: 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

In gcc, how to mute the -fpermissive warning?

放肆的年华 提交于 2020-01-10 07:55:28
问题 I am including a file from a third-party library that raises an error that can be downgraded to a warning with -fpermissive . But because I do not want to "pollute" my compilation log with these warnings, I want to completely disable this messages. So far, I set the -fpermissive option with a diagnostic pragma when including the file; something like: #pragma GCC diagnostic push #pragma GCC diagnostic warning "-fpermissive" #include <third-party-file.h> #pragma GCC diagnostic pop Since gcc

Does the program execution always start from main in C?

老子叫甜甜 提交于 2020-01-09 10:33:15
问题 Must program execution start from main, or can the starting address be modified? #include <stdio.h> void fun(); #pragma startup fun int main() { printf("in main"); return 0; } void fun() { printf("in fun"); } This program prints in fun before in main . 回答1: The '#pragma' command is specified in the ANSI standard to have an arbitrary implementation-defined effect. In the GNU C preprocessor, '#pragma' first attempts to run the game 'rogue'; if that fails, it tries to run the game 'hack'; if