Questions tagged [conditional-compilation]

Compilation of certain parts of source code will be included/excluded. This can be often reached by pre processing the source code in some way. Including/Excluding parts of the source may be controlled by pre processor keywords.

Filter by
Sorted by
Tagged with
2 votes
1 answer
32 views

Only generate debugging output while running tests

Rust/Cargo have nice build and testing functionality that are built in, and you can differentiate how you want to build and run code with cargo build, cargo build --release, cargo run, and cargo test. ...
  • 1,614
-3 votes
0 answers
27 views

Use different module names based on defines

I tried to define the module name based on parameters or defines imported from a package, but got the following error in Vivado: module `ifdef DEFINE1 ModuleName1 ( `elsif DEFINE2 ModuleName2 ...
1 vote
1 answer
83 views

What are the consequences of a feature-gated enum variant?

What if a library crate defines an enum that has a variant that is feature-gated? #[non_exhaustive] enum Foo { A, B, #[cfg(feature = "some-feature")] Gated, } This is a ...
  • 1,943
0 votes
1 answer
32 views

Where in the world is "Conditional Compilation Symbol?"

If you've transition to VS2022 from the older version of VS, you'll notice the "Conditional Compilation symbols" is gone! See my solution below on how to find it.
  • 1,237
-3 votes
2 answers
98 views

Check directory exists or not in C, Using preprocessor

I wanted to #define some macros based on whether particular directory is present in Linux, I can't use any fopen/directory/stat API's here since they are exposed during compilation phase Example, Need ...
-2 votes
1 answer
56 views

How to hide a secret in a Flutter flavor?

I want my app to have two flavors: users' version and developers' version. Apparently, it is to be done with Flutter flavors. I want developers' version to contain a "secret developers' key"....
  • 5,244
0 votes
0 answers
25 views

How to link/integrate code dependent from different 3rd Parties in Uniy3D

We have a System in Unity3D which builds small Apps and is mainly based on interfaces. For different solutions, I integrate a few different packages or Assets. these dependencies conflict with each ...
0 votes
1 answer
70 views

C conditional compilation - is there a more elegant way

I am refactoring a few c code files based on a variable set in Makefile, and I realize that there are lots of code that need conditional compilation across the files. I find that I'm doing this a lot: ...
0 votes
2 answers
111 views

Conditional compilation (constexpr if) and "ISO C++ forbids zero-size array"

With the following code: #include <algorithm> constexpr int DATA_SIZE = 5; constexpr int A_ARRAY_ALLOWED_SIZE = 5; constexpr int A_ARRAY_SIZE = std::min(A_ARRAY_ALLOWED_SIZE, DATA_SIZE); ...
  • 2,254
3 votes
0 answers
64 views

Cargo feature flags still compile all default targets

I have a feature flag "my-flag" defined in the features section of the Cargo.toml file. I've applied the attribute #[cfg(feature = "my-flag")] for conditional compilation at ...
  • 396
0 votes
0 answers
17 views

How to only build a NuGet Package into a specific Configuration (f.e. Debug only)

I am building a C# Application where users can opt-in to advanced diagnostics. Assume I'm using a NuGet-Package X but I only want it to be built using the Debug (or any other than Release) ...
  • 1
2 votes
4 answers
111 views

Cargo: How to include the entire directory or file in feature flags?

I'm working on a Rust project. I'm using Cargo feature flags for conditional compilation of the some code. There are cases where I have to include the entire file in the feature flags so doing so ...
  • 396
1 vote
2 answers
87 views

How to configure fallback value of constant if multiple #[cfg(...)] don't match?

I am trying to set value of constant based on target_os. I want to achieve something like this: #[cfg(target_os = "linux")] const MAP_FLAGS: libc::c_int = libc::MAP_POPULATE; #[cfg(...
  • 6,898
2 votes
0 answers
51 views

How to document feature-gated derived traits?

I understand that I can use the cfg_attr attribute to conditionally derive Trait implementations for types. For example, A struct MyStruct which always implements Clone, Copy, and Debug, but which ...
  • 1,943
1 vote
2 answers
59 views

Control 2 different pages UI from within one single class

I know this question may be nonsense, but I've been thinking about it for some time. I am developing a Xamarin Forms app that works both on Windows and on Android, and they share most of the code. ...
  • 11
3 votes
2 answers
92 views

How can I import modules only if they exist?

I am doing advent of code, which is a collection of 25 programming problems, one for each of day of the advent. I structure each day in it's own separate file/module, so for example year 2021 day 7 ...
  • 95
1 vote
0 answers
56 views

How is Ada and GPR supposed to handle conditional compilation? [duplicate]

I'm rewriting C source to Ada and on some places there is conditional compilation for handling different platforms, such as windows vs posix, DEBUG, or architecture. For what I can tell neither Ada ...
  • 4,914
1 vote
0 answers
54 views

Is it possible to combine two flags defined in SWIFT_ACTIVE_COMPILATION_CONDITIONS?

In our project we have two compilation conditions defined in our project's xcconfig files which we're using like so: #if FOO_VERY_LONG_NAME && BAR_VERY_LONG_NAME ... #endif For ...
0 votes
1 answer
45 views

Handling OS function name mismatch with macros

My current code is: int my_func(int a) { #ifdef _WIN32 return _func(a); #else return func(a); #endif } But I think it would be better if it was something like: #ifdef _WIN32 #...
  • 141
3 votes
3 answers
2k views

.NET MAUI: How to ensure that Android platform specific code is only executed on supported Android versions?

I have various implementations of a partial class DeviceServices to provide platform specific implementations of certain device or OS specific features for Android, iOS and so on. My app is targeting ...
  • 3,237
1 vote
0 answers
32 views

C# Conditional Attribute: What about using directives?

I am writing a c# application that currently uses #if IOS using Plugin.Firebase.iOS; #else using Plugin.Firebase.Android; #endif and then it uses it later on: void SomeMethod(Events events) { #if IOS ...
  • 3,517
1 vote
1 answer
64 views

Webpack modules loaders parsing file multiple times

I'm currently using Webpack (with Laravel Mix) with ifdef-loader module for conditional compilation, but as soon I introduced html-webpack-plugin to automatically clean output folder before each ...
  • 1,959
0 votes
0 answers
46 views

Conditional compilation for EF Core at design time

I have a custom projection method, and you can see here that it's giving me an error, but only when doing the EF Core build. While I can't figure out how to actually solve that issue, I am hoping I ...
  • 7,422
0 votes
1 answer
102 views

Preprocessor macro to check for x64 platform with ONE condition?

In a C project, at some places, I'd like to compile different code, depending on whether or not the compilation happens for x64. Of course, CPP macros are the route to go. However, on this page (which ...
  • 3,919
2 votes
1 answer
183 views

Is there a difference between use of _WINDOWS_ and _WIN32 / _WIN64 macros?

Is there a difference between: #if defined(_WIN32) || defined(_WIN64) and: #ifdef _WINDOWS_ I know that it is necessary to use defined() when there is more than 1 condition.
  • 1,365
0 votes
1 answer
177 views

How to check Kconfig flag in C source code

I am new to Linux and Kconfig. I have a config enabled in a Kconfig file as follows : config ENABLE_MY_CONFIG bool "Enable my config" default n help Say Y if you want to ...
  • 3,603
3 votes
2 answers
409 views

How can I run cargo check/test individually on each feature of my Cargo.toml?

Cargo features allow conditional compilation, so the final build will have just specific groups of features which can be filtered by the final user. Now depending on the complexity of a library crate, ...
  • 5,696
6 votes
1 answer
228 views

Why does invalid code annotated by `#[cfg(test)]` still cause the build to fail?

Running cargo build will succeed for the following code: #[cfg(test)] mod tests { #[test] fn func() { let x = 1; sss } } but will fail for this code: #[cfg(test)] mod ...
  • 369
1 vote
1 answer
63 views

type 'X' is not a direct type of 'Y' - but with std::conditional

I have a Base class, two classes inheriting from that base class (they are slightly different from each other) and a Last class which can either inherit from Derived1 or Derived2 based on a template. ...
  • 43
0 votes
0 answers
30 views

why the redfinition in c

//-----a.h------- #ifndef ELEMTYPE #define ELEMTYPE typedef int ElemType; #endif //------test.c----- #include <stdio.h> #define ELEMTYPE typedef double ElemType; #include "a.h"; int ...
0 votes
1 answer
138 views

ifdef and make: Invalid syntax in conditional

I am new in make. I was just trying to check whether the input given to the make is correct or not and if the user does not give any value, I'll just set it to '0'. The error encountered are as ...
  • 3
3 votes
1 answer
88 views

What does "#if ..." (with an ellipsis) do?

I was doing some studying of the windows header files and I came upon a preprocessor statement that I didn't recognize. I've been searching for any information on this statement for about a week and I ...
  • 65
0 votes
0 answers
32 views

Designing unified codebase to handle two separate XML Schemas

Background I have one XSD schema file that describes hundreds of individual messages in a messaging format used for communication between systems. We will call this XSD version 1. I have another XSD ...
1 vote
0 answers
110 views

Doxygen skip ifdef

I am using doxygen to document my code and I have one concern. I want doxygen to record and disclose the header files. I am using ceedling for my unit tests and I often have to add helper functions ...
  • 379
0 votes
0 answers
55 views

How to give ifdef variable in terminal in makefile

When compiling with “make xxx=0”, the message displayed on the terminal is not displayed, but when compiling with “make xxx=1”, a message about the build process is displayed on the terminal window ...
4 votes
2 answers
412 views

cfg attribute with arbitrary constant expression

I have the following const: const IS_WSL: bool = is_wsl!(); and I'd like to be able to use this with the cfg attibute to perform conditional compilation. Something like: #[cfg(const = "IS_WSL&...
  • 8,660
4 votes
1 answer
1k views

In VS2022, how do I specify a conditional compilation symbol for a build configuration?

In VS2017, I had several different build configurations that built an application in different ways. One configuration would produce the default application. Another build configuration would ...
  • 12.3k
3 votes
1 answer
667 views

Has Swift compilation condition for SwiftUI preview environment?

Objective C has preprocessor, Swift has compilation conditions that allows to use different code for different environments, for example for debug or release build: #if DEBUG print("debug ...
2 votes
0 answers
106 views

Conditional import of Java Vector API

I am playing around with Vector API in JDK 17. Since it is not available on older version of Java, I wonder if it is possible to conditionally import it. So that if Vector API is available, then Java ...
  • 5,273
0 votes
2 answers
478 views

Conditional compilation using ifdef-loader with Angular 13 and Webpack?

I have an Ionic application that relies heavily on conditional compilation where I include or exclude blocks of code based on a set of config values similar to how m4 works. I had been using https://...
  • 1,901
2 votes
1 answer
145 views

Conditional compilation in Haskell other than using CPP

The CPP extensions allows conditional compilation, e.g. {-# LANGUAGE CPP #-} #ifdef DEBUG -- some debug code #endif It works fine, of course, but it's quite clumsy and non-idiomatic. Is there really ...
  • 1,901
2 votes
2 answers
105 views

typedefing a pointer recognized by C to an inner C++ class

I have a class that I want to share between C and C++, where C is only able to get it as a pointer. However because it is an inner class it cannot be forward-declared. Instead this is what our current ...
  • 478
0 votes
2 answers
81 views

Specialize member func for integral template arg with c++17

I'm trying to use std::enable_if_t and std::is_integral_v templates to specialize a mem-func of a class. I read this, but it is about common functions instead of member-function. I mimic it and write ...
  • 1,383
3 votes
1 answer
159 views

How to declare a pointer to a nested C++ class in C [duplicate]

I have a nested class in C++ that I want C code to be able to use. Because it is nested I cannot forward declare it to C, so instead we have code like this in a shared header file: #ifdef __cplusplus ...
  • 478
4 votes
0 answers
166 views

Can an App Extension be conditionally included in a build?

I'm starting work on 2 app extensions, and I'd like to set up my builds as follows: Builds intended for the App Store should not include either extension Builds intended for TestFlight should include ...
18 votes
1 answer
723 views

Is there a way to enforce correct spelling of features?

Let's assume I have the following feature defined in Cargo.toml: [features] my_feature = [] And the following code lives in src/lib.rs: #[cfg(feature = "my_feature")] fn f() { /* ... */ } #...
  • 11.5k
0 votes
1 answer
125 views

Display code in appropriate #ifdef block according to the value of identifier

I have a C codebase with source files using #ifdef blocks all over. There are multiple identifiers and corresponding ifdefs (with the ifdefs nested to multiple levels). While viewing the code in vim, ...
  • 7
2 votes
1 answer
365 views

Set PLSQL_CCFLAGS for the schema

There are several schemas in my database. Some of them are for debugging (we call them DEV schemas) and the others are for production. To differ the DEV schemas from others we use one package which ...
  • 657
0 votes
1 answer
82 views

C++ headers inclusion order, strange behaviour

I'm writing some library and want to have some "optional" class methods (or just functions), declared or not, dependent on other library inclusion. Say, I have a class SomeClass with method ...
0 votes
2 answers
75 views

#ifdef python3 print_with_parantheses #else print_using_python2_style #endif

Is there a way to achieve something like "conditional interpretation" in python similar to the conditional compilation c pre-processor directives allow? I would like to use the same code in ...

1
2 3 4 5
15