Skip to main content
Filter by
Sorted by
Tagged with
0 votes
1 answer
108 views

I want to remove the comma characters inside __VA_ARGS__. I have found a FOR_EACH implementation, which kind of solves it, but gives cluttered error messages when there is a mistake. My problem has ...
clash's user avatar
  • 101
Advice
0 votes
6 replies
199 views

I need to layout a structure in two different ways depending on the endianness of the target platform. Currently I'm using an additional pre-compile phase to run a program to test the endianness, and ...
Alnitak's user avatar
  • 341k
-4 votes
1 answer
82 views

I'm experimenting a bit with trying to build NodeJS 24.11.1 with GCC 13.4.0 on an older OS X system, mostly as a can-it-be-done project. Regardless of the reasons, among the hurdles that could be ...
RJVB's user avatar
  • 820
5 votes
1 answer
167 views

The same code, one generated by macros and the other handwritten, produces different results.I'm lost and don't know how to fix it. my environment is follow: vs2019, msvc2019_64, c++14 if using ...
user31892351's user avatar
2 votes
1 answer
115 views

I wrote my "Result" macro header, using C23 and some of the newest features: #pragma once #include <stdio.h> #include <stdlib.h> #define __RESULT_EAT_PARENS(...) __VA_ARGS__ ...
Karesis's user avatar
  • 23
1 vote
1 answer
64 views

This snippet is mostly from the Cloak wiki, C Preprocessor tricks, tips and idioms, with DEFER2, X1, and X2 added by me for ease of referencing things in this post. #define EMPTY() #define DEFER(id) ...
Harry's user avatar
  • 4,031
8 votes
6 answers
872 views

If it's possible, I would like to define a macro that would take number of arguments in function template ARGS_COUNT and make a template with all argument types being enumerated and output being ...
kusok_kvarka's user avatar
0 votes
2 answers
111 views

I have #file debug.h #ifndef PDEBUG #define PDEBUG(msg ...)\ logger_write(logger_stdout, (struct log) {\ .level_target = LOGLEV_DEBUG,\ .message = msg,\ .properties = strdict_make_from_va(...
user973223's user avatar
3 votes
2 answers
150 views

Please consider the following minimal example: #include <stdio.h> // Compile with: // gcc -g -o myprogram main.c //#define SPECIAL typedef struct { int id; char name[50]; float value; } ...
sdbbs's user avatar
  • 5,948
-2 votes
1 answer
139 views

#include <stdio.h> #define n 16 #define a -2.0 #define b 2.0 #define c (b-a)/n int main() { printf("%lf\n",5.0*c); } Outputs 1.250000 But if i change (b-a)/n to b/n-a/n it outputs ...
Peter's user avatar
  • 139
5 votes
1 answer
127 views

Lets say I have some manner of type safety macro based on _Generic, which I use to wrap an actual function call to make it type safe: #include <stdio.h> void print (int i) { printf("%d\n&...
Lundin's user avatar
  • 220k
1 vote
1 answer
172 views

Im trying to build old version of openwrt and Im getting this error #error "Please port gnulib freadahead.c to your platform! Look at the definition of fflush, fread, ungetc on your system, then ...
Vido's user avatar
  • 242
4 votes
1 answer
181 views

Problem Description C++17 introduced the __has_include preprocessor expression, which has the following two forms: __has_include(header-name) __has_include(header-name-tokens) For the first form, ...
Pluto's user avatar
  • 1,124
0 votes
1 answer
108 views

This does not answer my need. I do not want to generate an error, I want to adapt the behavior of the software depending on the condition. Example: #if ( sizeof(unsigned long) == 4 ) # define a 5 #...
virolino's user avatar
  • 2,331
5 votes
2 answers
126 views

I'm confused about the behaviour of unrecognised preprocessor directives according to specifically the C90 standard. In C90, a group-part is defined as either (with question marks used to indicate its ...
resoinaut's user avatar
  • 113
4 votes
2 answers
139 views

Consider the macros: #define B(y,z) B##y##z #define C(z) C##z #define A(x) B(x, C(x)) A(1) Everywhere I look, people say arguments are replaced first. Which implies this should happen: A(1) => B(1,...
Sid Datta's user avatar
  • 1,159
4 votes
2 answers
228 views

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 ...
rayhanrjt's user avatar
1 vote
3 answers
155 views

In my code I use printf-like LOG(const char* fmt, ...) macro. Under the hood it prints/logs to different output destinations (file, console, debugger output). It's my own macro, so it does printf ...
Pavel P's user avatar
  • 17.3k
0 votes
1 answer
25 views

I have a function that allows access to system variables based on a lookup code. The lookup code has an enum type. typedef enum SystemVariable_e { INT_SYSTEM_VAR_1 = 0x10, INT_SYSTEM_VAR_2 = 0x20 ...
Derek Tables's user avatar
2 votes
1 answer
147 views

#define STRIP_PARENS(...) __VA_ARGS__ #define L(X) \     X((a, b)) \     X((c, d)) #define FIRST(x, ...) x #define FA_INNER(...) FIRST(__VA_ARGS__) #define FA(x, ...) FA_INNER(x) #define FAL(args) ...
muser's user avatar
  • 215
6 votes
0 answers
128 views

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 /* ...
jozxyqk's user avatar
  • 17.7k
2 votes
3 answers
164 views

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(&...
George Robinson's user avatar
3 votes
0 answers
163 views

I want to define a assembly to read register from arm64. Code is like the following: asm volatile( "str <reg> [%0]\n" : : "r"(value) : "...
songzh's user avatar
  • 65
4 votes
3 answers
204 views

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) ...
Josh Op's user avatar
  • 145
13 votes
5 answers
3k views

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 {$...
AlainD's user avatar
  • 6,815
3 votes
2 answers
133 views

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 ...
Andreas's user avatar
  • 10.5k
0 votes
0 answers
38 views

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 ...
ilinm's user avatar
  • 9
4 votes
1 answer
122 views

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 ...
Sergey Kolesnik's user avatar
1 vote
0 answers
122 views

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 "...
Eric Sun's user avatar
  • 973
3 votes
2 answers
125 views

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 ...
Alphin Thomas's user avatar
6 votes
1 answer
98 views

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", ...
Andreas's user avatar
  • 10.5k
-1 votes
1 answer
83 views

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_, ...
Olumide's user avatar
  • 5,915
3 votes
1 answer
124 views

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)" ...
elechris's user avatar
  • 718
1 vote
1 answer
109 views

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 ...
Dominik Kaszewski's user avatar
1 vote
2 answers
174 views

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 //...
Waleen _'s user avatar
2 votes
1 answer
98 views

prog.c has #include <stdio.h> #define STR(x) _STR(x) #define _STR(x) #x int main() { const char *s = STR(MYPATH); puts(s); } and is compiled with cc -...
ST0's user avatar
  • 317
0 votes
0 answers
168 views

I want to define a preprocessor macro with parameter N that constructs a declaration for C++ user-defined literal with suffix _uN. #define DEFINE_LITERAL(N) int operator""_u##N(const char* s)...
Paweł Bylica's user avatar
1 vote
1 answer
113 views

I am building a Linux kernel module, the source code is C++ based. One of the src files named A.cpp always has a build failure. A.cpp indirectly includes two header files: asm/current.h and bits/...
Ryan's user avatar
  • 51
2 votes
1 answer
114 views

Say my code looks like this: gpios.h: #define GPIO_BASE 0x08000100 #define GPIOA ((GpioRegs *) (GPIO_BASE + 0x04)) #define GPIOB ((GpioRegs *) (GPIO_BASE + 0x0C)) #define GPIOC ((GpioRegs *) (...
Edward Falk's user avatar
  • 10.2k
0 votes
0 answers
63 views

I would like to display a warning message when the user calls a macro, but only once per compilation unit, so they don't drown in error messages. Something like that: int main() { MACRO(42); // <-...
Dorian's user avatar
  • 632
1 vote
2 answers
100 views

I just know that #pragma once is not part of the C standard but rather part of the preprocessor. In that case, does that make the preprocessor not part of the C standard? So, are the C programming ...
jaroenchoke's user avatar
1 vote
1 answer
90 views

I have a macro like this: #define ptapply(pt, ret_type, identifier, ...) ((ret_type (*)()) pget(pt, identifier))(pt __VA_OPT__(,) __VA_ARGS__) pget returns a void * which I cast into a function ...
hansoko's user avatar
  • 389
1 vote
3 answers
168 views

I'm developing an API looking like GLib logging. My API can also disable these functions when the flag -DDEBUG isn't passed to GCC. That means, there are no residues in the binary, all these debug ...
Eternal Dreamer's user avatar
0 votes
2 answers
128 views

For instance, imagine you want to enable only one compilation target so you do something like this: // uncomment ONE of these #defines to compile for a specific target #define TARGET_1 #define ...
aeatdistek's user avatar
0 votes
3 answers
80 views

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 ...
Alex Kiselev's user avatar
2 votes
1 answer
2k views

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 ...
Newbyte's user avatar
  • 3,957
4 votes
1 answer
153 views

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 ...
Zebrafish's user avatar
  • 16.3k
4 votes
2 answers
187 views

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 ...
Abdulmalek Almkainzi's user avatar
0 votes
1 answer
113 views

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 ...
bakar bakar's user avatar
1 vote
0 answers
124 views

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 ...
yurich's user avatar
  • 157

1
2 3 4 5
120