1,906 questions
Advice
0
votes
7
replies
135
views
C Preprocessor: foreach/macro expansion with loop context
So I've been using this code for generating such statements following This Reddit post:
#define LOOP(seq) END(A seq)
#define BODY(x) int x;
#define A(x) BODY(x) B
#define B(x) BODY(x) A
#define A_END
#...
0
votes
1
answer
78
views
Automate removal of div/span attributes for code clean-up and easier merging
<span class="SpellingError SCXO166867203 BCX8" style="margin:0px;padding:0px;background-repeat:repeat-x;background-position:left bottom;">bv</span><span class="...
0
votes
0
answers
555
views
Docling Hyperlink Extraction Issue : I am using docling to convert pdf to markdown file, but hyperkink not preserved in markdown file after conversion
I’m currently using the Docling library in Python to extract text from PDF files. While it works well for retrieving visible text, I’ve noticed an issue with hyperlinks. Specifically, the library only ...
2
votes
1
answer
74
views
Why in Erlang do i need to specify `-module` if it is equal to filename?
For example, if I create file jopa.erl with this code inside ...
-module(jopa).
...everything compiles without errors
However, if I put this code inside jopa.erl ...
-module(lol).
and try to compile....
12
votes
7
answers
2k
views
Construct an std::array at compile time in C++17 using the preprocessor
I am developing a C++17 framework that has optional third-party dependencies and I'd like to construct an std::array that contains the names of the available dependencies.
The CMake file sets ...
0
votes
0
answers
69
views
Preprocessing Data with Scale and then Binarize in Python
I am working on some proof of concepts for ML and want to try an unusual scaling method. I would like to group my data and then "scale" it and apply a binarize to that data. Basically I ...
3
votes
0
answers
59
views
Can the GNU Assembler perform all macro expansions in a file and then output compilable code without macros?
Is there a way to have the GNU assembly process a source file that contains macros, expand them, and then output the expanded equivalent code in a form that could be assembled by as? Basically, I'm ...
3
votes
1
answer
161
views
__FILE__ without full path
The C++ macro __FILE__ typically includes the full path (with many compilers).
For my tracing, I want just the file name, not the full path.
Is there a built-in macro for this in any version of C++ or ...
4
votes
2
answers
227
views
How to accurately count tokens in a C program? Do preprocessor directives like #include and #define count?
I'm studying how tokenization works in C programming, especially for examination purposes. I want to understand how many tokens are present in the following C code and how preprocessor directives are ...
0
votes
0
answers
79
views
Using WXUSINGDLL has no effect on the linkage
my wxWidgets application has multiple C++ projects (one executable and all the other static libraries). I am using Visual Studio 2022 with a solution having Debug and Release configurations only for ...
1
vote
1
answer
169
views
How to disable all SIMD related feature macros in clang?
By default, clang defines some SIMD related macros:
~ $ 0 clang++ -dM -E -x c /dev/null | grep -i sse
#define __SSE2_MATH__ 1
#define __SSE2__ 1
#define __SSE_MATH__ 1
#define __SSE__ 1
These can be ...
2
votes
1
answer
115
views
How to nest #if and #elif definitions inside a #ifdef macro in Inno Setup
I'm trying to do the following:
[Code]
#define TextMacro "Hello2"
procedure InitializeWizard();
var
Mode: Integer;
begin
#ifdef TextMacro
#if TextMacro == "Hello"
...
2
votes
2
answers
91
views
Multiple definition linking error on macro expansion with expansion guards
I have a header file that introduces a macro that declares a Stack structure and some asociated functions that work with that struct. Header file (Stack.h) content is shown below:
#ifndef STACK_H
#...
7
votes
1
answer
159
views
Document function-like macros without evaluating if/else with Doxygen
I am trying to document a header file which has different "overloads" when parsed by C or C++.
#ifdef __cplusplus
/// myfuncA
void myfuncA();
/// MYMACRO_A
#define ...
3
votes
2
answers
125
views
Can a C program execute successfully if main() is defined as a macro?
We know that main() is the entry point of a C program. But what happens if we define main as a macro, like this?
#define main something_else
Will the program compile and run correctly?
How do ...
2
votes
3
answers
113
views
why does this compile & how to test if a macro is defined with vs without a value?
The following code compiles without error:
//#define FOO
#if FOO
sdjlfs
#endif
int main(){
return 0;
}
although I would expect it to fail at line 2, because the following doesn't compile (...
3
votes
1
answer
161
views
Is there a way to have one preprocessor macro start a raw literal string and another end it?
For example
#define BEGIN_RAW R"(
#define END_RAW )"
const char* foo =
BEGIN_RAW
this is a
raw string
END_RAW;
This doesn't work. It looks like the preprocessor itself resolves the ...
1
vote
2
answers
140
views
Conditional compilation using the preprocessor
I have a list of functions generated in a Makefile and dumped into a file that looks something like:
DEF(foo)
DEF(bar)
DEF(baz)
The intent is that this file will be used like so to define a list of ...
1
vote
1
answer
40
views
How to interpret differences in accuracy curves after applying different data augmentations in CNN training?
I trained a CNN for emotion recognition and used two different transformation pipelines for image preprocessing:
Simple Transformation:
TRANSFORM = transforms.Compose([
transforms.Resize((64, 64)),...
1
vote
2
answers
174
views
How does the C preprocessor handle not repeating includes and copying more than once
I recently learned how the c compiler actually works and there is a specific configuration that i do not understand : When I write a header it looks like this:
#ifndef HEADERNAME
#define HEADERNAME
//...
0
votes
2
answers
158
views
Optional parentheses for C variadic macro (i.e. both function-like and object-like)
Background
I have some macros of the form ATTR(XXX(...)). ATTR processes XXX into a macro ATTR_IMPL_XXX(...), and XXX can have a variable number of arguments (these variadic args are just passed to ...
0
votes
0
answers
53
views
How can I use z88dk-z80asm preprocessor to expand a variable into a filename?
In z88dk-z80asm I want to include a binary file using a string literal, where a part of the file name is passed as a command line variable/symbol (-D) to the compiler:
binary "...
0
votes
0
answers
143
views
Token-pasting operator ## in C preprocessor [duplicate]
Can I use the token-pasting operator ## in the following way:
#define NameIs 0xFFFF
#define PASTE NameIs
#define foo(text) My##text##Andrey
foo(PASTE);
...and don't get -> "MyPASTEAndrey&...
1
vote
0
answers
31
views
Define preprocessors for dependency projects
I am using visual studio 2019.
I have a project A (dll) depending on a project B (static library).
So when building A, it builds indeed B first.
So I would like to have a preprocessor defined when ...
4
votes
1
answer
283
views
How to print constexpr in C23 at compile-time?
I'm migrating my codebase from C17 to C23 on ARM-GCC and would like to be able to print the evaluation of constexpr calculations at compile-time for debugging purposes.
In C17, I used #pragma message ...
1
vote
1
answer
221
views
What is the correct usage of __has_include
If I don't know where I might find the xyzzy header, should I write (e.g.):
#if __has_include("xyzzy")
# include "xyzzy"
#elif __has_include(<xyzzy>)
# include <xyzzy>
#...
1
vote
1
answer
80
views
Source code positions after CPP macro expansion
I have the following Haskell file that contains a CPP macro.
#define FOO( x, y ) x ++ y
foo =
FOO("a",
"b"
++ "c")
bar = 1
When I call cpphs on this ...
3
votes
1
answer
63
views
C++ preprocessor check if macro equals two double quotes
I'm running into an issue with a macro that is generated from an environment variable in platform.io:
-D SXM_VERSION=\"${sysenv.SXM_VERSION}\"
As you can see SXM_VERSION forced to start and ...
0
votes
2
answers
166
views
Is this why a project can fail to compile if two headers include each other?
I'm trying to understand why two mutually included headers (each header including the other) doesn't work the way you might expect. I was wondering if my reasoning is correct:
If you have FooHeader.h:
...
0
votes
1
answer
113
views
run only preprocessor using ESP-IDF
I would like to see my esp-idf code after preprocessing (see which code inside of #ifdef will be compiled).
I tried adding "add_compile_optins(-E)" in my main CMake file, but the build ...
1
vote
0
answers
124
views
How to make immutability a default behaviour with C preprocessor
I think that the benefits of data immutability outweigh the inconvenience of the implicit mut qualifier. That's why in my opinion it should be the default. I know that some functional languages ...
0
votes
0
answers
199
views
Getting preprocessor and compiler output in VS 2022
Because I wanted to learn more about the preprocessor, I enabled "Preprocess to a file" for my project (project properties, C/C++, preprocessor), so it looked like this:
However, at some ...
4
votes
2
answers
161
views
Where in the specification is this way of macro expansion avoidance defined?
Given the following code:
#include <limits>
#include <Windows.h>
int main()
{
std::numeric_limits<double>::max();
}
I can avoid the preprocessor macro expansion of max() from ...
0
votes
0
answers
56
views
Simple for loop in C preprocessor [duplicate]
My actual use case if for C++. I'm trying to reduce the amount of typing I need to do while explicitly instantiating a template. E.g.,
template <int N>
void myFunc(std::array<float, N> ...
0
votes
2
answers
170
views
How to dynamically expand a variable in CPP
#include <iostream>
using namespace std;
const string getFileNameAsVarName(string filename, int lineNo)
{
string s = "";
for (char c : filename)
{
if (c > 'a' && ...
0
votes
1
answer
97
views
c++ efficient explicit template instantiation for several template parameters
I am writing a c++ library where I deal with plenty of templated classes and free functions . Example (header + source file containing a free function):
#ifndef MY_FUNCTION_HPP
#define MY_FUNCTION_HPP
...
2
votes
1
answer
73
views
boost wave generates runtime assertion
I am developing a 'C' macro-expander with Visual Studio 2022 & Boost.Wave (through vcpkg). I based the application on the advanced_hooks sample that ships with boost.
The application works ...
0
votes
2
answers
168
views
Is there an easy one-line way to define a C preprocessor macro only if it doesn't already exist?
I have a file with hundreds of preprocessor macros of the form...
#define foo (bar)
Is there an easy one-line way to define each one only if it doesn't already exist?
For a single macro once could do ...
0
votes
1
answer
133
views
Why are my preprocessor-macros slower or faster than manual writing seemingly random?
Yesterday at work, my colleague claimed that preprocessor macros were slower than writing variables and functions manually. The context is that we have a class in which member variables are sometimes ...
1
vote
1
answer
53
views
Removing bi-grams after tokenization for TfidfVectorizer
I'm attempting to remove bi-grams that are created by TfidfVectorizer. I'm using text.TfidfVectorizer so that I can use my own preprocessor function.
Test strings and preprocessor function:
doc2 = ['...
1
vote
1
answer
43
views
Understanding GCC Compilation: Preprocessing vs Linking with Libraries
I have a question regarding compilation with GCC.
I have a slight confusion that I believe I've figured out but would like confirmation on. In the first compilation step, preprocessing (cpp) organizes ...
-2
votes
1
answer
174
views
why division doesn't work with #define numbers? [duplicate]
#define BLUR 2
#define LEN (2 * BLUR + 1) * (2 * BLUR + 1)
using namespace std;
int main()
{
cout << 50 / LEN; // result is 50
}
the expected result is 2 but it's 50. I try another numbers ...
1
vote
1
answer
126
views
How to remove comments from the scala code
Any ideas how to remove comments from the scala code so that:
Nested multi line or single line comments are removed.
Comments inside string literals are not removed.
Code can have single and triple ...
0
votes
1
answer
84
views
"Preprocessing" a Python function, to avoid excess evaluation of conditional logic
I am writing some Python code that includes functions with two sets of parameters. The first set of parameters will be different every single time the function is called. The second set of parameters ...
2
votes
2
answers
164
views
Doxygen not generating the documentation for a function declared inside `#ifdef X` `#endif`
I am making a library in C and writing internal documentation for it using Doxygen 1.9.4. I have a following header, included both from library source (in this case LIBRARY_SOURCE is defined) and from ...
3
votes
2
answers
108
views
Is there any way to get the C precompiler to use a mathematical result when concatenating symbols?
I have a C macro that concatenates bits together in order to resolve to other macros. I'll demonstrate using an admittedly pointless macro called MULT which multiplies two numbers. So long as I pass ...
0
votes
1
answer
30
views
Trouble Extracting and Utilizing Tokens Across Thread Groups Using JSR223 Preprocessor
I am trying to use JSR223 preprocessor to extract token from login and using it in other thread group of my test plan, but i am not getting it , i tried to add debugger , but token is not present in, ...
1
vote
1
answer
102
views
In the C preprocessor does #define incorporate previous #defines?
With these #defines without arguments
#define r 31
#define UMASK (0xffffffffUL<<r)
#define LMASK (0xffffffffUL ^ UMASK)
will UMASK be identical to (0xffffffffUL<<31) and LMASK be ...
1
vote
1
answer
270
views
How to Align Preprocessor Directives (#) with Code Blocks Using clang-format?
I am using clang-format to format my C++ code. However, I want to align preprocessor directives (including the # sign) with the surrounding code blocks. Currently, clang-format aligns the directives ...
0
votes
1
answer
310
views
Add and retrieve GCC_PREPROCESSOR_DEFINITIONS value in Swift
I have multiple target created in my project. Now I'm planing to add a string UUID to all the targets GCC_PREPROCESSOR_DEFINITIONS aka preprocessor macro.
I'll add this to Alpha, Beta, Lite & Prod....