conditional-compilation

Conditional Compilation - Check Scheme

荒凉一梦 提交于 2019-11-29 13:04:30
In a Swift project before I've been able to perform a simple compiler check to see which scheme is running, then conditionally include code or not. For example: #if MyScheme Add code here #endif But for some reason, in my Objective-C project, this doesn't seem to be working. Should this work the same way? Or does the Swift compiler have some advancements which allow this kind of behaviour? Use #ifdef //example for debug scheme #ifdef NDEBUG Add code here #endif And you can define your preprocessor macros here Hope this helps 来源: https://stackoverflow.com/questions/45659435/conditional

Conditional compilation in C++ based on operating system

心已入冬 提交于 2019-11-29 10:51:31
I would like to write a cross-platform function in C++ that contains system calls. What conditional compilation flags can I check to determine which operating system the code is being compiled for? I'm interested mostly in Windows and Linux, using Visual Studio and GCC. I think it should look something like this: void SomeClass::SomeFunction() { // Other code #ifdef LINUX LinuxSystemCall(); #endif #ifdef WINDOWS WindowsSystemCall(); #endif // Other code } My gcc (4.3.3) defines the following Linux-related predefined macros: $ gcc -dM -E - < /dev/null | grep -i linux #define __linux 1 #define _

Swift: iOS Deployment Target Command Line Flag

北城余情 提交于 2019-11-29 08:58:26
问题 How do I check the iOS deployment target in a Swift conditional compilation statement? I've tried the following: #if __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_8_0 // some code here #else // other code here #endif But, the first expression causes the compile error: Expected '&&' or '||' expression 回答1: TL;DR? > Go to 3. Solution 1. Preprocessing in Swift According to Apple documentation on preprocessing directives: The Swift compiler does not include a preprocessor. Instead, it takes

How do I check if one of multiple macros is defined in a single #ifdef?

岁酱吖の 提交于 2019-11-29 03:29:56
I have some C++ code, and want to perform an action if the __APPLE__ or __linux macros are defined. If I did it as a normal if conditional, it would be easy using || : if (something || something) { .. code .. } But as of what I know there is no || operator for #ifdef statements. How would I check if __APPLE__ or __linux is defined using a single #ifdef statement? You can't in a single #ifdef would a single #if do instead? #if defined(__APPLE__) || defined(__linux) this also works if you prefer #if defined __APPLE__ || defined __linux In my C++ there is. #if defined(__APPLE__) || defined(_

How to programmatically change conditional compilation properties of a VBA project

孤者浪人 提交于 2019-11-29 01:30:29
I'm currently working on a VBA code generator/injector that adds VBA functionality to Excel workbooks by using the VBA Extensibility. This all works fine. However, the original code that is injected uses conditional compilation, referring to some global conditional compilation arguments: Is there any way I can programmatically modify/add the conditional compilation arguments of a VBA project? I checked all properties of the VBProject but couldn't find anything. Peter Albert Inspired by this approach , shown by SiddharthRout, I managed to find the following solution using SendMessage and

How to #ifdef by CompilerType ? GCC or VC++

≯℡__Kan透↙ 提交于 2019-11-29 01:12:37
问题 I used #ifdef Win32 for safe calls alike sprintf_s but now I want to build project with MinGW and it's just wrong now. I need to use #ifdef VC++ or somehow like that. Is it possible? 回答1: See the "Microsoft-Specific Predefined Macros" table of Visual C predefined macros You could check for _MSC_VER . 回答2: #ifdef __clang__ /*code specific to clang compiler*/ #elif __GNUC__ /*code for GNU C compiler */ #elif _MSC_VER /*usually has the version number in _MSC_VER*/ /*code specific to MSVC

Conditionally display block of markdown text using knitr

人走茶凉 提交于 2019-11-28 18:56:32
I would like to edit a single rmarkdown (Rmd) document with a list of "problems", each followed by its solution. Each solution may contain the results of R console, but also some explaining (markdown and LaTeX formatted) text. Besides, I would like to knitr it in 2 versions: with and without the solutions, changing the source as less as possible, and compiling. I know I can use a logical variable in order to conditionally evaluate R code and show plots and R output, but I don't know how to show/hide blocks of (markdown and LaTeX) formatted text, unless I put all that text into R character

c++ #ifdef Mac OS X question

两盒软妹~` 提交于 2019-11-28 18:12:42
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", "TARGET_MAC_OS", "MACINTOSH", etc. What is the current and correct declaration to put in the #ifdef statement

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

寵の児 提交于 2019-11-28 17:08:23
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). 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. Svetlozar Angelov Conditional Compilation You can use the defined operator in the #if directive to use expressions that evaluate to 0 or 1 within a preprocessor line. This saves you from using

When compiling for multiple targets in XCode, how do i ensure that certain files will not be included one target

不问归期 提交于 2019-11-28 09:05:04
问题 I searched for a long time on stackoverflow using every keyword I could think of to solve this. I am programming for iphone and I have a lite and paid version of my app. I followed the instructions here Creating Lite Versions of iPhone Games / Apps for duplicating the target. This works and now I am working on slimming down the lite version. Main problem? Images. The lite version needs to have several hundred less images than the paid version. So, I made 2 groups in XCode. One "Folder Group"