Questions tagged [preprocessor-directive]
Instructions to a preprocessor that control how it modifies source text
596
questions
1
vote
2
answers
261
views
Conditional compile-time warning in C++
I am implementing my own analogue of std::expected for C++17, and I am writing a method that takes a function and invokes it on the successful value of the expected. If the expected contains error, ...
0
votes
1
answer
33
views
How to pass the CMake binary path to C++ on Linux?
My project has this simplified directory structure:
+-src
| +-CMakeLists.txt
+-example
| +-CMakeLists.txt
+-_builds
| +-win
| | +-src
| | +-example
| +-linux
| | +-src
| | +-example
+-CMakeLists.txt
...
-1
votes
0
answers
31
views
Using regex in C++ pre-processor directives [duplicate]
I am trying to find an easy way to redefine multiple class methods uses in my code if the given package is not installed. Am I able to use regex to match object.method(params) in #define ... ...
1
vote
2
answers
103
views
Getting unexpected results when using macros with arguments [duplicate]
#include <stdio.h>
#define big(a, b) a > b ? a : b
#define swap(a, b) temp = a; a = b; b = temp;
int main() {
int a = 3, b = 5, temp = 0;
if ((3 + big(a, b)) > b)
swap(a, ...
0
votes
1
answer
36
views
Conditional compilation of code only when running in Visual Studio 2022
We have some mocking code that I'd like to run ONLY when running in VS2022. Does anyone know if there is a preprocessor variable (or some other way) I can use to check for this condition, that the ...
2
votes
1
answer
38
views
Is there a way to ignore warnings in dependent packages? Is there a way to #if an os that the compiler doesn't know about?
I am using Swift Playgrounds to do App Development. One of my dependencies has some code like this:
#if os(visionOS)
That causes my app to have a warning due to Swift Playgrounds not being updated ...
0
votes
1
answer
29
views
Using correct #define preprocessor directive syntax to replace/rename text/function names
What is the correct syntax using the preprocessor directive #define, to replace/rename the following snippet of code from:
printf("\nrxBuffer: %s", rxBuffer);
fprintf(fpOut, "\nReceived ...
0
votes
1
answer
72
views
How can I use Preprocessor Directives to Conditionally Include Specific CSS Snippets?
Problem:
I have two build configurations. Each has its own preprocessor symbol: DEV and PROD.
I would like each build to have its own background-image color.
For C# files, I know that I can use ...
1
vote
1
answer
81
views
Preprocessor directive to detect running on macOS using the Designed for iPad target
Apple provides a runtime isiOSAppOnMac property of ProcessInfo to detect if running on a Mac using the Designed for iPad target.
I'd much rather use a preprocessor directive than having to do runtime ...
0
votes
0
answers
39
views
How to define a pre-processor directive in the Immediate Window?
I have some code that I want to run in Visual Studio's Immediate Window. It depends on a preprocessor directive. When I try to #Define it in there, I get error CS1525: Invalid expression term ''. My ...
0
votes
1
answer
55
views
Is it possible to pass MSBuild's property in Visual Studio's test explorer?
I know I could do something like this:
dotnet test myproject.csproj /p:IsTest=true
and in myproject.csproj:
<PropertyGroup>
...
<DefineConstants Condition=" '$(IsTest)' == '...
0
votes
1
answer
106
views
Preprocessing directives GPU
I have a C/C++ package where I make use of some GPU acceleration methods, CUDA for Nvidia hardware and using OpenCL for non-Nvidia hardware. I also have SIMD functions specific to Intel CPUs and some ...
1
vote
0
answers
55
views
Understanding deferring macro
I am trying to understand the deferring macro hierarchy. Does this make sense?
// Online C++ compiler to run C++ program online
#include <iostream>
#define EMPTY()
#define EVAL_1(...) ...
0
votes
1
answer
189
views
which field in clang-format to define not to indent after preprocessor directive?
current codes after applying clang-format is:
#ifndef CEEDLING_TEST
static
#endif
void
Measurement(const uint16_t *buff)
{
g_rmsValue1ms = Get1msRmsValue(buff);
g_rmsValue60ms = ...
0
votes
0
answers
21
views
Using preprocessor directives to make a given program compile successfully without modifying the code
I am given the following program which does not compile, and my task is to use preprocessor directives to make it compile (I have no prior knowledge of these directives):
#include <iostream>
#...
0
votes
1
answer
83
views
How to use C# #if debug (preprocesser directive) in release mode without changing files in production environment?
I would like to understand if I can use the #if in my development scenario. I would like to capture the execution time each method in the production environment.
For that I am thinking to use the ...
1
vote
4
answers
180
views
Is it possible to compute factorial value of a proprocessor value during compile time in C?
#define num 7 \\ user can change this
#define size ???? \\I want this value (factorial of num) to be computed during compile time
int array[size][num];
I want to define array globally, but its ...
0
votes
0
answers
90
views
Preprocessor directives are not getting collapsed when I fold a function with non-indented pragmas in VSCode
I'm making a unity game and trying to fold a function, but my preprocessor directives (checks if it's on android or not) are not getting collapsed. Only code until the directive is collapsed.
Code ...
1
vote
0
answers
281
views
C# preprocessor #if check for #nullable enable directive
New versions of C# have a directive to allow object types to be assumed as non-null by default. I have a unity library that's in use by older and newer projects, and I want to support both of them but ...
0
votes
2
answers
534
views
How to fix the macro expansion problem in C
How to fix the macro expansion issue below ?
#define GET_VAL 3,2
#define ADD_VAL(val0, val1) ((val0) + (val1))
void foo()
{
int res = ADD_VAL(GET_VAL);
}
The ...
0
votes
1
answer
83
views
Usefulness of preprocessor directives [closed]
I was looking into some advanced topics in C and stumbled on the ## operator, and the example given was something like this.
#define GLUE_HELPER(x, y) x##y
#define GLUE(x, y) GLUE_HELPER(x, y)
#define ...
0
votes
5
answers
332
views
Define custom syntax "until" in C
I expect I can do something like this:
int i = 0;
until (i == 2){
printf("yes\n");
i++;
}
Without telling detail about what until does, I'm sure reader know what is the algorithm from ...
1
vote
1
answer
93
views
C Macro Whitespace
I am unable to accomplish the following because whitespaces are ignored(?) in the preprocessor. I understand that this is part of the standard, but I'm wondering if there's a work around using ...
0
votes
0
answers
18
views
#ifdef and #define equivalent in Python (to switch between sorting by date and cost)? [duplicate]
I have a class in Python:
class purchase:
name: str
day: int
month: int
year: int
date: int #works by Julian Day Number
cost: Decimal
I want to write a function to sort a list ...
0
votes
1
answer
123
views
C++ - How to use preprocessor if statements(#if, #elif, #endif) inside a macro? [duplicate]
I am currently developing a program that I intend to be portable. I have access to both Windows and macOS, and I would like to be able to debug easily on both. When error handling, I want to have ...
1
vote
2
answers
176
views
What is the '_u' data type in this #define declaration?
Hope I'm phrasing this question correctly... I have begun working through some coding examples for a micrcontroller device, and I see many expressions similar to the following:
#define REG_CONFIG _u(...
0
votes
1
answer
50
views
'Expected primary expression' when expanding C Macro
I'm trying to default initialize a config struct that consists of some fields including another subordinate config struct - with a macro:
LiveDemo
#include <cstdio>
#define ...
0
votes
1
answer
52
views
Why don't I need to use the -MT option for dependency generation when I save my object files to a separate directory?
I have a (GNU)Makefile that gives the .o files a name that puts them in a separate directory. If I'm reading the GCC documentation on preprocessor options correctly, then all directory components and ...
1
vote
2
answers
113
views
typedef declaration contains #define directive alias
I use two libraries in my project; let's say A and B for the sake of this question. Unfortunately, I ended up in the following situation:
In A.h:
#define ssize_t long
In B.h:
typedef long long ...
0
votes
1
answer
68
views
Does self-defined headers count as preprocessor directives
All the statements with the symbol # are known as preprocessor directive. My question is does self-defined headers count as preprocessor directive?
# include "example.cpp" // Does it count ...
0
votes
1
answer
151
views
Set preprocessor symbol in QtCreator code model only
I'm working on a CMake-based project that contains both C++ and CUDA source files, and has some headers meant to be included by both languages.
For these header files, I'd like to see the result of ...
0
votes
1
answer
617
views
Defining C# preprocessor directive at the Solution level [duplicate]
I have a question Based on This question
Is it possible in C# to define a preprocessor directive at the solution level rather than the project level.
Motivation: I have a common library, and there ...
-2
votes
1
answer
51
views
Why this doesn't show 1.50 as output [duplicate]
#include <stdio.h>
#define f(n) (2-(1/n))
int main() {
printf("when n =2, %.2f\n", f(2));
return 0;
}
Answer is 0.00.Why the output isn't 1.50
0
votes
2
answers
241
views
.net Exclude "Debug" code from Release dll (c#)
Is it possible to exclude code that is marked as Debug exclude from Release ddl like:
#if DEBUG
Console.WriteLine("DEBUG");
#endif
#if RELEASE
Console.WriteLine("RELEASE");
#endif
...
0
votes
1
answer
46
views
Is it possible to swap two tokens with macros in C++
Consider this C++ program:
#include <cstdio>
#define FOO BAR
#define BAR FOO
#define QUOTE(X) #X
#define EXPAND(X) QUOTE(X)
int main()
{
printf("%s expands to %s\n", QUOTE(FOO), ...
0
votes
0
answers
42
views
Usages inside #if statement is not being indexed
I have two classes. There is #if statement, that decides which class should be used.
Example:
public class DebugTool { }
public class ReleaseTool { }
...
#if RELEASE
var tool = new ReleaseTool();
#...
1
vote
0
answers
44
views
Why is my user defined definition in Xcode 13 not working?
For debug vs. release purposes I am trying to create preprocessor definitions so that my code can be written just once as:
#if DEBUG_LEVEL_1
self.status = printSimDir()
#endif
I have tried, and ...
0
votes
1
answer
537
views
How to see intermediate files created during C++ compilation process
When building an application in C++, I want to see all my intermediary files generated during the process like .o file, .i file, .asm file etc. But when I jump into explorer in windows, it shows ...
3
votes
2
answers
273
views
Visual Studio C++ preprocessor-define fails with path starting on "u"
That's right I want to supply a path as preprocessor define (properties->configuration->c/c++->preprocessor)
MY_PATH=c:\$(WindowsSdkDir)\um
But this hits me upon use with
E1696 cannot open ...
1
vote
1
answer
195
views
Error: operator "defined" requires an identifier
I have been searching for an hour about this seemingly obvious question, and read several other posts including this one with the same title, but I am still struggling to find a convincing answer. ...
0
votes
1
answer
173
views
How to avoid redefining preprocessor directives of static library?
I have a question related to preprocessor defines and static linkage. I have two cpp libraries, whereof the static Library B consumes thet static Library A.
Library A uses preprocessor directives for ...
0
votes
1
answer
53
views
I can't divide my working code into class-specific header/cpp files without getting an C2504 error : base class undefined
Using Visual Studio 2022, I'm making a simple text RPG in plain C++. I've been playing around with Object Oriented Paradigm and the code is working as intended when in a single file, but upon dividing ...
0
votes
1
answer
330
views
GNU Assembler .print expression instead of string
According this https://sourceware.org/binutils/docs/as/Print.html#Print, I only can print string instead of expression.
I tried this one line assembler
.print "Hello" //No Error
.print 1+2 //...
0
votes
1
answer
341
views
What is Python equivalent of the C++ macro preprocessor directive?
I have a repeated piece of code in my python code that I can’t factorize in a function because it analyses the call stack.
from traceback import extract_stack as es, format_list as fl
class Pmf
...
1
vote
3
answers
107
views
What is the idea/notion behind using '#' as comments in Python while C uses '#' for pre-processor directive?
My guess:
In Python:
// was used for floor division and they couldn't come up with any other alternative symbol for floor division so they couldn't use // for comments in Python.
# was an available ...
2
votes
1
answer
136
views
Should I cater to MSVC by checking MSVC_LANG?
MSVC does not properly define __cplusplus, unless one specifies the /Z:cplusplus switch.
Now, in a library I'm maintaining, I have some conditional compilation logic such as:
#if __cplusplus >= ...
1
vote
1
answer
46
views
Unity3d edit mode test cases hot to set platform
I have following code
#if UNITY_IOS && !UNITY_EDITOR
public static MyPlugin Current = new MyPluginIOS();
#elif UNITY_ANDROID && !UNITY_EDITOR
public static MyPlugin Current = ...
3
votes
1
answer
766
views
How to pass preprocessor directive to MSBuild via dotnet publish
I have an ASP.NET Core 6.0 WebApi solution with SPA. The default template builds the SPA by default by running PublishAngular target below.
WebApi.csproj file:
<Project Sdk="Microsoft.NET.Sdk....
3
votes
2
answers
508
views
#if Vs if constexpr
Which one is more appropriate for compile-time configurations (such as debug/release), preprocessor directives, or if constexpr?
#define DBG
#if DBG
// some code
#endif
// ---------------------------...
0
votes
1
answer
69
views
Why are my Preprocessor Directives locked
I've done lots of research but haven't found any answers yet.
I'm working on a plugin to run inside a proprietary program called Autodesk Revit. This plugin needs to be distributed to 3x different ...