5,949 questions
0
votes
0
answers
64
views
How is it that postprocessed file compiles but preprocessed file does not? [duplicate]
Below is "main.cpp". It does does not compile.
I can run the preprocessor on it
g++ -E main.cpp -o result.cpp and get a new .cpp file.
If I then compile result.cpp like this g++ result.cpp -...
5
votes
0
answers
86
views
How to avoid macros from X11 polluting other third party code?
Is there a nice way to wrap X11/Xlib.h and X11/X.h includes so they don't leak the following macros everywhere? It's an endless source of pain:
#define Bool int
...
#define None 0L /* ...
2
votes
3
answers
141
views
What characters are the legal terminators of C preprocessor keywords like #if #else #elif #endif
What characters are the legal terminators of C preprocessor keywords/tokens like #if, #ifdef, #ifndef, #else, #elif, #endif, etc...
#ifdef COMING
printf("Hello World\n");
#else
printf(&...
3
votes
0
answers
125
views
How to make a macro in C to parameterize register?
I want to define a assembly to read register from arm64. Code is like the following:
asm volatile(
"str <reg> [%0]\n"
:
: "r"(value)
: "...
3
votes
2
answers
138
views
"Extensible" C generics
I'm trying to make an implementation of a Vector in C (yes, I know, this has been done to death), generic across any types used. So far I have an implementation something like:
#define Vector(T) ...
13
votes
5
answers
2k
views
In C++, can I use a preprocessor directive inside of a statement on one line, like I can do in Delphi?
The C/C++ ternary operator is great:
int x = (someFlag) ? -1 : 1;
Delphi has a nice feature where preprocessor directives can be written on one line. Two examples:
x := {$IFDEF DBG_MY_SYMBOL} -1 {$...
3
votes
2
answers
115
views
Accessing structure member that is identical to macro name
Is there a way to access a structure member which is identical to a macro name? Consider this code:
struct test {
int foo;
};
#define foo bar
int main(int argc, char *argv[])
{
struct test ...
0
votes
0
answers
34
views
C++ Processing each argument of variadic macro individually [duplicate]
I have a two macros - MACRO1(x, y) and MACRO2(x, ...)
I want for MACRO2(x, a, b, c...) to expand into MACRO1(x, a), MACRO1(x, b), MACRO1(x, c), ... but can't wrap my head around how to do that. I've ...
3
votes
1
answer
98
views
Google Test: How to get correct line numbers in test output for parameterized tests?
I'm using Google Test with parameterized tests and want to see the correct line number in the test output so I can quickly find the specific test case that failed.
Problem
When a test fails, the ...
1
vote
0
answers
37
views
nvim treesitter highlight for "#if...#elif...#endif" preprocessors
I am using nvim + nvim-treesitter to parse and highlight my code. There is a problem on C source code #if...#elif...#endif preprocessor block.
Say I have the following code
// test.c
#include "...
3
votes
2
answers
105
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 ...
6
votes
1
answer
88
views
Why does an empty preprocessor command still evaluate to something?
Please take a look at this small code snippet:
#include <stdio.h>
#define BAR
int main(int argc, char *argv[])
{
int foo = 1;
foo = BAR(1, 2, 3);
printf("%d\n", ...
-1
votes
1
answer
73
views
Using the Boost preprocessor to statically initialize an array
How can I use the Boost preprocessor to statically initialize an array with string and pointer pairs as shown below
#include <string>
struct Node;
struct Port
{
Port(std::string name_, ...
3
votes
1
answer
87
views
Double Quotes not escaped in eclipse shell command for preprocessor define
I'm using eclipse on Windows to build a C-project.
I create a preprocessor define containing git status summary git status -s.
This is my define symbol:
GIT_STATUS="$(shell git status -s)"
...
1
vote
1
answer
83
views
Lambda with structured bindings inside macro call
This may be related to How to correctly forward structured binding arguments in a macro , but I feel the real problem is not the same, so may have a different solution.
I want to pass a lambda as a ...