5,925
questions
0
votes
3
answers
64
views
C preprocessor name definition
I want to create some kind of smart name definition using a preprocessor in my library project. So I have for example a timer named TC0 and some additional names for interrupts handler like ...
1
vote
0
answers
60
views
How do I define a C/C++ preprocessor variable in Meson?
I want to conditionally define a variable that I then can use within C/C++ sources to conditionally compile some code, like this:
#ifdef MY_MESON_VARIABLE
// some code
#endif
How do I go about ...
4
votes
1
answer
96
views
Is there a way to conditionally include a header or import a module depending on a switch/flag?
I've tried:
#ifdef USE_CPP20_MODULES
#define IMPORT_OR_INCLUDE(module_name, include_filepath) \
import module_name;
#else
#define IMPORT_OR_INCLUDE(module_name, include_filepath) \
#include ...
4
votes
2
answers
148
views
Detect a parenthesized macro argument in C
I want a macro to detect whether the passed arg is surrounded by parentheses or not, and call a different macro if so.
e.g.
#define FOO(obj) BAR obj
#define BAR(...) func(__VA_ARGS__)
#define BAR
If ...
0
votes
1
answer
52
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
100
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 ...
4
votes
2
answers
140
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 ...
1
vote
2
answers
78
views
File compilation order in C with circular dependency
/*
* structs.h
*
* Created on: 14 Jun 2019
*/
#ifndef STRUCTS_H_
#define STRUCTS_H_
#include <stdint.h>
#include "line_mask.h"
#define CONFIG_LINE_NUM 80
...
1
vote
2
answers
83
views
gcc Preprocesor failed on #if
I have strange problem as gcc preprocesor failed on #if directive.
Sample code:
#include "stdio.h"
enum BoardTypes{
Board_IO_WithAdc,
Board_IO_WithEnc,
Board_PakelcIn,
...
2
votes
1
answer
135
views
Should a source file end with new line or not? What about backslash + newline?
If we don't end a source file with a new line character but just a } after main(), then the clang compiler (in strict mode
-std=c17 -pedantic-errors) infamously complains:
error: no newline at end of ...
1
vote
1
answer
93
views
How to call preprocessor in c
I've been trying to call the preprocessor to create a .i file from a .c file using the cpp.exe preprocessor file.
When using this command: cpp file.c > file.i, this is what is shown at the terminal:...
1
vote
0
answers
54
views
MSVC doesn't seem to resolve recursive macros the same way GCC does [duplicate]
I have the following recursive macro:
#define MAP_OUT
#define A(x) x B MAP_OUT (x)
#define B(x) x A MAP_OUT (x)
#define EVAL0(...) __VA_ARGS__
#define EVAL4(...) EVAL0 (EVAL0 (EVAL0 (__VA_ARGS__)))
#...
0
votes
0
answers
101
views
Possible to split word into char list in the C preprocessor
I have a preprocessor macro, called INSTR(...). It takes in a comma separated list of chars, and outputs a compile time constant number depending on the input. This macro currently works, and can be ...
0
votes
2
answers
129
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
0
answers
51
views
Is there a way to #include contents of Raw string without the delimiters? [duplicate]
I'm writing a thing for Arduino. The piece for the webpage currently has:
const char index_html[] =
#include "index.html.h"
;
where index.html.h contains:
R"MaRkEr(<!DOCTYPE ...