conditional-compilation

Using conditionals in project's main unit - IDE destroys code

依然范特西╮ 提交于 2019-12-06 02:11:00
I'm building a windows service application which has a configuration to compile it as a basic windows application. The main project file for the exe includes conditionals which determine whether the project is being compiled as a service application or as a windows forms application. The problem is, when I do something which makes the project code change, the code gets destroyed and broken. For example, a line which says Application.Initialize; becomes AppliApplication.Initialize; and the line which has {$R *.RES} gets cut down to S} , and most of my conditionals get deleted. I'm wondering if

Are conditional expressions broken within packages?

余生长醉 提交于 2019-12-06 00:00:35
问题 Consider the following snippet: requires designide, rtl, vcl, {$IF RTLVersion < 19.0} // E2026 Constant expression expected //{$IF CompilerVersion = 22.0} // same as above vcljpg; {$ELSE} vclimg; {$IFEND} It seems to be absolutely syntactically correct. However, the compiler chokes on it and reports Constant expression expected . What really happens here? Technical: currently tested on XE (15.0.3953.35171) only. Of course, workaround suggestions are welcome too. 回答1: I found the same issue in

How to use /NODEFAULTLIBS option in compilation?

有些话、适合烂在心里 提交于 2019-12-05 18:48:25
I have a solution explorer contains 2 projects. For one project I have enabled /clr with /mdd . For parent project I have /mtd and no clr support. When I compile this I get two linker errors including the below one: Link warning link 4098:Default lib can conflict with other lib use /NODEFAULTLIBS library So my question is how to use /NODEFAULTLIBS in compilation. Thanks in advance. First you need to work out which library is causing the conflict, if you can. Does the link warning tell you anything? Then you need to open the property pages for this project, and go to Linker -> Command Line. In

Will the expression provided to Debug.Assert be evaluated in a release build?

廉价感情. 提交于 2019-12-05 16:19:32
Say I have a rather expensive assertion: bool IsCompatible(Object x, Object y) { // do expensive stuff here } If I test this assertion with: Debug.Assert(IsCompatible(x,y)); Will IsCompatible be executed in release builds? My understanding is that Debug.Assert being marked as [Conditional("DEBUG")], calls to it will only be emitted in debug builds. I'm thinking that this won't prevent the expression from being evaluated in release mode though, since the method call may have side effects, only the passing of the result to Debug.Assert wouldn't be emitted. Is that correct? Should I be doing: #if

Why do people use #ifdef for feature flag tests?

江枫思渺然 提交于 2019-12-05 15:31:35
问题 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

gcc conditional compilation

我只是一个虾纸丫 提交于 2019-12-05 09:52:06
I'm learning about conditional compilation and I think that I understand it well so far. Now, if I have the code: #ifdef UMP_TO_FILE //do something here... #endif and I run: gcc myprogram.c -DUMP_TO_FILE Then, the code block "//do something here..." gets compiled. Now, my question is: What exactly the -DUMP_TO_FILE flag does? I think that the flag is "-D" and it defines the macro "UMP_TO_FILE", but I want to be sure of the syntaxis and "gcc --help" does not tell me anything about this and maybe I don't know how to search for this on the Internet!! Thank you very much for sharing your knowledge

Conditional compilation symbols not being defined

馋奶兔 提交于 2019-12-05 08:33:15
I am having trouble getting Visual Studio to behave as I would expect it. I created 2 configuration profiles. One has the symbol FOO defined and the other has the symbol BAR defined. And I have this code: static class MyClass{ #if FOO public static string const MyData="foo defined"; #endif #if BAR /*yes, I know #elif would work here too.. just trying to be simple*/ public static string const MyData="bar defined"; #endif } and then later in another file I have if(MyClass.MyData=="foo defined")..... Well, in my application, I get an error that MyClass.MyData is not defined. Also, if I have it on

#ifdef with multiple tokens, is this legal?

萝らか妹 提交于 2019-12-05 08:07:29
Today I came across some C++ code that contains an #ifdef clause like this: #ifdef DISABLE_UNTIL OTHER_CODE_IS_READY foo(); #endif Note the space between "DISABLE_UNTIL" and "OTHER_CODE_IS_READY". Essentially there are two tokens specified in the #ifdef line. My question is, is this legal C++ code? (g++ compiles it without any errors, and it apparently just ignores the second token). And if it is legal, should the second token have any effect? [C++11 16.1] , [C++11 16.5] and, incidentally, [C99 6.10.1/4] all say that this is invalid. if-group : # if constant-expression new-line group opt #

Is it better to use `#ifdef` or inheritance for cross-compiling?

守給你的承諾、 提交于 2019-12-05 07:07:11
To follow from my previous question about virtual and multiple inheritance (in a cross platform scenario) - after reading some answers, it has occurred to me that I could simplify my model by keeping the server and client classes, and replacing the platform specific classes with #ifdefs (which is what I was going to do originally). Will using this code be simpler? It'd mean there'd be less files at least! The downside is that it creates a somewhat "ugly" and slightly harder to read Foobar class since there's #ifdefs all over the place. Note that our Unix Foobar source code will never be passed

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

好久不见. 提交于 2019-12-05 06:55:11
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 Jon 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 the conditional attribute to perform conditional compilation. You can define a symbol, but you cannot