conditional-compilation

C# !Conditional attribute?

主宰稳场 提交于 2019-11-28 06:40:34
Does C# have a not Conditional ( !Conditional , NotConditional , Conditional(!) ) attribute? i know C# has a Conditional attribute : [Conditional("ShowDebugString")] public static void ShowDebugString(string s) { ... } which is equivalent 1 to: public static void ShowDebugString(string s) { #if ShowDebugString ... #endif } But in this case i want the inverse behavior (you have to specifically opt out ): public static void ShowDebugString(string s) { #if !RemoveSDS ... #endif } Which leads me to try: [!Conditional("RemoveSDS")] public static void ShowDebugString(string s) { ... } which doesn't

Does the bitness of the OS ever matter, or is it just the application I need to worry about?

我怕爱的太早我们不能终老 提交于 2019-11-28 02:14:41
问题 Some assumptions: (correct me if wrong) Ignoring 16-bit stuff, VBA can be run on 32 or 64-bit Office hosts. 64-bit Office can only be run on a 64-bit OS, whereas you can run 32-Bit office on a 32 or 64-bit version of Windows/macOS/other Operating System. As of VBA7, we have the LongPtr type, which becomes a Long on 32-bit Office ( #Win64 = False ), LongLong on 64-bit Office ( #Win64 = True ), regardless of the OS bitness My question: In APIs that deal with pointers (addresses in memory), does

Preprocessor directives across different files in C#

南楼画角 提交于 2019-11-27 23:46:30
I know that I can use preprocessor directives in C# to enable/disable compilation of some part of code. If I define a directive in the same file, it works fine: #define LINQ_ENABLED using System; using System.Collections.Generic; #if LINQ_ENABLED using System.Linq; #endif Now, I'm used in C++ at putting all this configuration directives inside a single header file, and include it in all files where I need such directives. If I do the same in C# something doesn't work: //Config.cs #define LINQ_ENABLED //MyClass.cs #define LINQ_ENABLED using System; using System.Collections.Generic; #if LINQ

Is it possible to conditionally compile to .NET Framework version?

别来无恙 提交于 2019-11-27 22:53:06
I can recall back when working with MFC you could support multiple versions of the MFC framework by checking the _MFC_VER macro. I'm doing some stuff now with .NET 4 and would like to use Tuple in a couple of spots but still keep everything else 3.5 compatible. I'm looking to do something like: #if DOTNET4 public Tuple<TSource, TResult> SomeMethod<TSource, TResult>(){...} #else public KeyValuePair<TSource, TResult> SomeMethod<TSource, TResult>(){...} #endif There are no builtin precompiler constants that you can use. But, it is easy enough create your own build configurations in VS with each

Use #ifdefs and #define to optionally turn a function call into a comment

痴心易碎 提交于 2019-11-27 20:40:15
Is it possible to do something like this #ifdef SOMETHING #define foo // #else #define foo MyFunction #endif The idea is that if SOMETHING is defined, then calls to foo(...) become comments (or something that doesn't get evaluated or compiled), otherwise it becomes a call to MyFunction. I've seen __noop used, but I don't believe I can use that. EDIT(s): I don't think I can really use a macro here, because MyFunction takes a variable number of arguments. Also, I'd like to make it so the arguments are NOT evaluated! (So doing something like commenting out the body of MyFunction doesn't really

Which conditional compile to use to switch between Mac and iPhone specific code?

北城余情 提交于 2019-11-27 17:50:01
I am working on a project that includes a Mac application and an iPad application that share code. How can I use conditional compile switches to exclude Mac-specific code from the iPhone project and vice-versa? I've noticed that TARGET_OS_IPHONE and TARGET_OS_MAC are both 1, and so they are both always true. Is there another switch I can use that will only return true when compiling for a specific target? For the most part, I've gotten the files to cooperate by moving #include <UIKit/UIKit.h> and #include <Cocoa/Cocoa.h> into the precompile headers for the two projects. I'm sharing models and

Is it possible to set the python -O (optimize) flag within a script?

大兔子大兔子 提交于 2019-11-27 16:36:24
问题 I'd like to set the optimize flag ( python -O myscript.py ) at runtime within a python script based on a command line argument to the script like myscript.py --optimize or myscript --no-debug . I'd like to skip assert statements without iffing all of them away. Or is there a better way to efficiently ignore sections of python code. Are there python equivalents for #if and #ifdef in C++? 回答1: -O is a compiler flag, you can't set it at runtime because the script already has been compiled by

Conditional Java compilation

谁说胖子不能爱 提交于 2019-11-27 15:00:03
I'm a longtime C++ programmer, new to Java. I'm developing a Java Blackberry project in Eclipse. Question - is there a way to introduce different configuration sets within the project and then compile slightly different code based on those? In Visual Studio, we have project configurations and #ifdef; I know there's no #ifdef in Java, but maybe something on file level? monojohnny You can set up 'final' fields and ifs to get the compiler to optimize the compiled byte-codes. ... public static final boolean myFinalVar=false; ... if (myFinalVar) { do something .... .... } If 'myFinalVar' is false

c++ #ifdef Mac OS X question

与世无争的帅哥 提交于 2019-11-27 10:46:59
问题 I am fairly new to C++. I am currently working on a group project and we want to make our classes compatible with both the lab computers (Windows) and my computer (Mac OS X). Here is what we have been putting at the top of our files: #ifdef TARGET_OS_X # include <GLUT/glut.h> # include <OpenGL/OpenGL.h> #elif defined _WIN32 || defined _WIN64 # include <GL\glut.h> #endif I realize this question has been asked before but my searches have been giving me conflicting answers such as "_MAC",

Boolean in ifdef: is “#ifdef A && B” the same as “#if defined(A) && defined(B)”?

风格不统一 提交于 2019-11-27 10:13:07
问题 In C++, is this: #ifdef A && B the same as: #if defined(A) && defined(B) ? I was thinking it wasn't, but I haven't been able to find a difference with my compiler (VS2005). 回答1: They are not the same. The first one doesn't work (I tested in gcc 4.4.1). Error message was: test.cc:1:15: warning: extra tokens at end of #ifdef directive If you want to check if multiple things are defined, use the second one. 回答2: Conditional Compilation You can use the defined operator in the #if directive to use