conditional-compilation

Allow use of member variable depending on preprocessor directives

无人久伴 提交于 2020-08-26 10:07:13
问题 Consider the following class: class Foo { public: #ifdef CONDITION int x = 0; #endif int y; int foo() { #ifdef CONDITION return ++x; #else return 0; #endif } } int x only exists when I define CONDITION - either through a #define CONDITION or as a preprocessor definition ( -D CONDITION ) This has the neat advantage that I can't compile it I use x by mistake somewhere when CONDITION isn't defined. For example: If, by mistake, I write something like: Foo f; f.x = 10; This will not be allowed to

How many lines are covered by the Rust conditional compilation attribute?

牧云@^-^@ 提交于 2020-02-24 09:14:05
问题 I'm trying to use a conditional compilation statement. Beyond defining a function that should only exist in a debug build, I want to define a set of variables/constants/types that only exist in the debug build. #[cfg(debug)] pub type A = B; pub type B = W; #[cfg(other_option)] pub type A = Z; pub type B = I; let test = 23i32; How many lines are actually "covered" by the conditional compile attribute in this case? Is it only one (what I would expect in this context)? Are there ways to ensure

Cython conditional compile based on external value

冷暖自知 提交于 2020-01-22 16:28:50
问题 I try to conditionally compile (or generate) to c code from a Cython pxd. I read that I can DEF to define aa value and IF to conditionally generate based on its value, but how can I get this value to get from outside of the pxd file? Specifically these two cases are interesting for me now: give some command-line define to Cython, preferrably through the Cython.Distutils setuptools way the extern-ed C header file defines some value, and conditionally define using Cython based on this value

Silverlight 3 and Silverlight 4 conditional xaml

江枫思渺然 提交于 2020-01-15 06:26:10
问题 I am working on a project right now that has to separate project files. One complies in Silverlight 3 and the other in Silverlight 4. The project creates a user control that is used in a couple other projects. Unfortunately one is in SL3 and cant be upgraded right now which is why a SL3 version of the control is needed. So far it has worked out fine but recently I tried to add a ViewBox to the control. This causes a problem because in SL3 it is located in the toolbox and in SL4 it is in the

Is there an easy way in C# to have conditional compilation symbols based on OS version

佐手、 提交于 2020-01-13 09:22:31
问题 I have a bunch of unit tests that need to be conditional compiled based on Windows OS version. This unit tests are testing TxF that is only available in Windows Vista and above. #if WIN_OS_VERSION >= 6.0 // Run unit tests #endif 回答1: I don't think there's a way to conditionally compile code based on OS version. The documentation for #define states (emphasis mine): Symbols can be used to specify conditions for compilation. You can test for the symbol with either #if or #elif. You can also use

Conditional compilation symbol for a .NET Core class library

左心房为你撑大大i 提交于 2020-01-11 04:47:04
问题 I have created a .NET Core R2 class library and have some common code that I use for several different platforms. Some of the code is not valid in the .NET Core platform and so I wish to wrap it around a conditional compilation symbol . I first searched the Internet to see if I could find a built-in symbol (like SILVERLIGHT for Silverlight applications and WINFX_CORE for Windows 8 applications), but I was not able to find any information, so I decided to create my own symbol. This also does

How do I check OS with a preprocessor directive?

岁酱吖の 提交于 2020-01-08 09:31:31
问题 I need my code to do different things based on the operating system on which it gets compiled. I'm looking for something like this: #ifdef OSisWindows // do Windows-specific stuff #else // do Unix-specific stuff #endif Is there a way to do this? Is there a better way to do the same thing? 回答1: The Predefined Macros for OS site has a very complete list of checks. Here are a few of them, with links to where they're found: Windows _WIN32 Both 32 bit and 64 bit _WIN64 64 bit only Unix (Linux,

How do I check OS with a preprocessor directive?

笑着哭i 提交于 2020-01-08 09:31:11
问题 I need my code to do different things based on the operating system on which it gets compiled. I'm looking for something like this: #ifdef OSisWindows // do Windows-specific stuff #else // do Unix-specific stuff #endif Is there a way to do this? Is there a better way to do the same thing? 回答1: The Predefined Macros for OS site has a very complete list of checks. Here are a few of them, with links to where they're found: Windows _WIN32 Both 32 bit and 64 bit _WIN64 64 bit only Unix (Linux,

How do I get emacs to change the compilation command on a per-buffer basis?

五迷三道 提交于 2020-01-07 06:37:15
问题 Suppose I have two code files, one is a small test script, the other is my main piece of code (both are c++ code files). I would like emacs to use different compilation commands for each of them (for example "make test_script" for one and "make release" for the other). What's the best way to do this? 回答1: You can use the compile-command local variable to the buffer. For instance, in one C++ source code: // Local Variables: // compile-command: "make release" // End: and you can change that in