conditional-compilation

Conditional DEBUG - Does it still compile into RELEASE code?

这一生的挚爱 提交于 2019-12-05 06:37:39
I know that if I mark code as DEBUG code it won't run in RELEASE mode, but does it still get compiled into an assembly? I just wanna make sure my assembly isn't bloated by extra methods. [Conditional(DEBUG)] private void DoSomeLocalDebugging() { //debugging } Yes, the method itself still is built however you compile. This is entirely logical - because the point of Conditional is to depend on the preprocessor symbols defined when the caller is built, not when the callee is built. Simple test - build this: using System; using System.Diagnostics; class Test { [Conditional("FOO")] static void

How to detect in runtime if some Compiler Option (like Assertions) was set to ON?

我是研究僧i 提交于 2019-12-05 05:43:32
What is the conditional to check if assertions are active in Delphi? I would like to be able to do something to suppress hints about unused variables when assertions are not active in code like procedure Whatever; var v : Integer; begin v := DoSomething; Assert(v >= 0); end; In the above code, when assertions are not active, there is a hint about variable v being assigned a value that is never used. The code is in a library which is going to be used in various environments, so I'd be able to test for assertions specifically, and not a custom conditional like DEBUG. You can do this using the

Conditional compilation for .NET 4 [duplicate]

你说的曾经没有我的故事 提交于 2019-12-05 02:19:39
This question already has answers here : Closed 6 years ago . Possible Duplicate: Conditional compilation and framework targets I have some code that works in .NET 4, but it does not work in .NET 3.5. In .NET 3.5 it requires to use interop calls to Windows. I would like using a "ifdef" to use a different code path in both cases (eventually I will deprecate the .NET 3.5 code). Is there a pre-defined directive value to identify when the code is compiled with .NET 4? Is there a good link with all the predefined directives ( DEBUG , TRACE , etc.)? The page below only gives the directives, but not

Java (Eclipse) - Conditional compilation

家住魔仙堡 提交于 2019-12-04 13:16:27
问题 I have a java project that is referenced in j2me project and in android project. In this project i would like to use conditional compilation. Something like... //#if android ... //#endif //if j2me ... //#endif I have been reading about this but i did not find anything useful yet. 回答1: You could use Antenna (there is a plugin for Eclipse, and you can use it with the Ant build system). I'm using it in my projects in a way you've described and it works perfectly :) EDIT: here is the example

Conditional Compilation in Referenced Assemblies

为君一笑 提交于 2019-12-04 07:22:22
I'm writing an assembly with some conditionally compiled members in it, e.g.: [Conditional("DEBUG")] public static void Log(string message) { /*...*/ } And using it like so: public void DoStuff() { Log("This will only appear on debug builds"); /* ... Do stuff ... */ } But when I give this assembly to someone to use in their project, I want them to be able to define whether or not DEBUG-conditional members are compiled. If that's not possible (e.g. the methods are just completely removed at compile-time), then is there any way to package multiple 'configurations' of an assembly (e.g. maybe with

Using conditional compilation symbols in MVC views

て烟熏妆下的殇ゞ 提交于 2019-12-04 03:09:56
问题 In "Properties" of my project I have the following: I want to check if TEST symbol exists, and only then, do some things. So I did what you see in the picture below and in the class it works. However this does not work in the views. The text in this block is gray even if TEST is defined! How can I cause it work if TEST is defined? 回答1: The problem is related to the fact that views are only compiled when you run your application so the TEST symbol that you defined is no longer applied by the

Choose a C binary according to the enviroment

久未见 提交于 2019-12-04 02:20:10
问题 I have compiled my code with specific flags (-Os, -O2, -march=native and their combinations) in order to produce a faster execution time. But my problem is that I don't run always in the same machine (because in my lab there are several different machines). Sometimes I run within a MacOS, or within a Linux (in both cases with different OS versions). I wonder if there is a way to determine which binary will be run depending on the environment where the binary will run (I mean cache size, cpu

Why do people use #ifdef for feature flag tests?

做~自己de王妃 提交于 2019-12-04 01:36:13
People recommend #ifdef for conditional compilation by a wide margin . A search for #ifdef substantiates that its use is pervasive. Yet #ifdef NAME (or equivalently #if defined(NAME) and related #ifndef NAME (and #if !defined(NAME) ) have a severe flaw: header.h #ifndef IS_SPECIAL #error You're not special enough #endif source.cpp #include "header.h" gcc -DIS_SPECIAL source.cpp will pass, obviously, as will source1.cpp #define IS_SPECIAL 1 #include "header.h" But, so will source0.cpp #define IS_SPECIAL 0 #include "header.h" which is quite the wrong thing to do. And some C++ compilers, passed a

Delphi conditional compilation in uses clause

痴心易碎 提交于 2019-12-04 00:23:00
问题 I am trying to modify my Delphi 2010 code to compile in XE7 (and want to retain the ability to compile it in 2010). So in the unit that houses my mainform I added conditional directives. The following works fine in 2010 uses {$IF CompilerVersion >= 24}System.Actions, {$ELSE}Actnlist,{$IFEND} Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs; But XE7 automatically adds a System.Actions at the end to create a uses clause that now has System.Actions declared twice (see

Debug Mode In VB 6?

本小妞迷上赌 提交于 2019-12-03 22:16:32
How can I do something similar to the following C code in VB 6? #ifdef _DEBUG_ // do things #else // do other things #end if It's pretty much the same as the other languages that you're used to. The syntax looks like this: #If DEBUG = 1 Then ' Do something #Else ' Do something else #End If It's easy to remember if you just remember that the syntax is exactly the same as the other flow-control statements in VB 6, except that the compile-time conditionals start with a pound sign ( # ). The trick is actually defining the DEBUG (or whatever) constant because I'm pretty sure that there isn't one