c-preprocessor

CPP/GPP in Fortran variadic macro (plus Fortran // concatenation)

青春壹個敷衍的年華 提交于 2019-12-20 01:03:15
问题 I'm trying to compile a huge, world-renowned numerical weather prediction code - written mostly in Fortran 90 - that uses cpp extensively, and successfully, with PGI, Intel and gfortran. Now, I've inherited a version where experts have added several hundred cases of variadic macros. They use Intel and fpp , which is presumably a little more Fortran-centric, and can get it all to work. I need to use gfortran, and have not been able to get cpp to work on this code with its new additions. A

CPP/GPP in Fortran variadic macro (plus Fortran // concatenation)

我的未来我决定 提交于 2019-12-20 01:03:07
问题 I'm trying to compile a huge, world-renowned numerical weather prediction code - written mostly in Fortran 90 - that uses cpp extensively, and successfully, with PGI, Intel and gfortran. Now, I've inherited a version where experts have added several hundred cases of variadic macros. They use Intel and fpp , which is presumably a little more Fortran-centric, and can get it all to work. I need to use gfortran, and have not been able to get cpp to work on this code with its new additions. A

How to guard move constructors for C++03 and C++11?

删除回忆录丶 提交于 2019-12-19 22:00:12
问题 This is similar to What differences, if any, between C++03 and C++11 can be detected at run-time?. But in this case, I want detection to occur via the preprocessor. How should we guard the move constructor (and move assignment) when the sources are used in both C++03 and C++11? Is the following sufficient (is move semantics something all C++ compilers adopted due to it being essential/core feature)? #if (__cpluplus >= 201103L) Foo(Foo&& other); #endif Or do I need to get into compiler

Conditional definition of elements in an X Macro

怎甘沉沦 提交于 2019-12-19 21:55:01
问题 Imagine I have an X Macro for a list of items defined something like this: #define X_MACRO(FN) \ FN(foo) \ FN(bar) \ FN(zip) This works great and I can call it to generate the same code templatized for each element, like: #define xstr(s) str(s) #define str(s) #s #define PRINT_X(E) void print_ ## E () { std::cout << str(E); }; X_MACRO(PRINT_X) This generates functions like void print_foo() { std::cout << "foo"; }; for each of the X_MACRO elements. So far, so good. Now, however, I want the list

Conditional definition of elements in an X Macro

我是研究僧i 提交于 2019-12-19 21:54:13
问题 Imagine I have an X Macro for a list of items defined something like this: #define X_MACRO(FN) \ FN(foo) \ FN(bar) \ FN(zip) This works great and I can call it to generate the same code templatized for each element, like: #define xstr(s) str(s) #define str(s) #s #define PRINT_X(E) void print_ ## E () { std::cout << str(E); }; X_MACRO(PRINT_X) This generates functions like void print_foo() { std::cout << "foo"; }; for each of the X_MACRO elements. So far, so good. Now, however, I want the list

Preprocessor and template arguments or conditional compilation of piece of code

丶灬走出姿态 提交于 2019-12-19 21:21:12
问题 How I can compile template function with pre-processor condition? Like that (but it is not working): template <bool var> void f() { #if (var == true) // ... #endif } 回答1: You can't. The preprocessor, as this names indicates, processes the source file before the compiler. It has therefore no knowledge of the values of your template arguments. 回答2: You can't do that with the preprocessor. All you can do is delegate the code to a separate template, something like this: template <bool var> void

defined(VARIABLE) not evaluated correctly by MSVC?

大兔子大兔子 提交于 2019-12-19 18:54:12
问题 Running the following code #include <iostream> #define FOO #define BAR defined(FOO) int main() { #if BAR std::cout << "BAR enabled!" << std::endl; #else std::cout << "BAR disabled!" << std::endl; #endif return 0; } in Visual Studio displays Bar disabled! , while running the same code in gcc or clang displays Bar enabled! . Is this a bug in the Microsoft compiler? What is correct according to the standard? 回答1: This is undefined behavior according to the standard. [cpp.cond], emphasis mine

How to define a define in C?

安稳与你 提交于 2019-12-19 12:49:12
问题 Is it possible to write a #define that defines a #define ? For example: #define FID_STRS(x) #x #define FID_STRE(x) FID_STRS(x) #define FID_DECL(n, v) static int FIDN_##n = v;static const char *FIDS_##n = FID_STRE(v) But instead: #define FID_DECL2(n, v) #define FIDN_##n v \ FIDS_##n FID_STRE(v) FID_DECL works fine but creates two static variables. Is it possible to make FID_DECL2 work and having define two defines? 回答1: No; preprocessing is performed in a single pass. If you want or need more

How to remove lines added by default by the C preprocessor to the top of the output?

你。 提交于 2019-12-19 12:24:58
问题 I'm trying to use the C preprocessor on non-C code, and it works fine except for creating lines like this at the top: # 1 "test.java" # 1 "<built-in>" # 1 "<command-line>" # 1 "test.java" The problem is that these lines aren't valid in Java. Is there any way to get the preprocessor to not write this stuff? I'd prefer not to have to run this through something else to just remove the first 4 lines every time. 回答1: If you're using the gcc preprocessor: -P Inhibit generation of linemarkers in the

Can I pass a preprocessor definition to the resource compiler through the command line?

旧街凉风 提交于 2019-12-19 08:54:17
问题 I'm currently trying to switch between a few different default Icons in a Visual C++ .rc file using #ifdef tags. The builds switching the #define value are being created through command line using MSBuild. The difficulty I have been running into is that using Visual Studio 2010, in order to pass a preprocessor definition to the resource compiler you must define it in the project settings (Config Properties -> Resources -> General). This makes it difficult to use an #ifdef tag because using