Questions tagged [c-preprocessor]
The c-preprocessor tag has no summary.
12 questions
6votes
3answers
333views
Implementation of arrays that store their size
In this code I implemented arrays that store their own size before the first element. To access it you need to go back exactly sizeof(size_t) bytes back. To free it,...
1vote
0answers
64views
General Purpose Utility Constants, Macros, and Functions
Overview: I have bundled together different macros and functions I often require in different projects into a single compilation unit (utils.h and ...
1vote
0answers
56views
Emulating C23's QChar * behavior for basename and strchrnul
To quote @Lundin from What is C23 and why should I care?: Bug fixes for a lot of library functions (search functions in particular): we can now pass a const-qualified pointer parameter to a library ...
4votes
1answer
281views
C - Force a macro argument to be a string literal
The requirement is to define a macro which takes a single argument that is a string literal. My first try at it was to surround it with empty string literals (I got this from Modern C): ...
7votes
2answers
755views
Consolidating GNU C's and C23's attributes
C23 has introduced attribute specifier sequences. Consequently, the header below attempts to conditionally define macros for these sequences (for my own use cases). In cases where a compiler does not ...
2votes
0answers
88views
Implementing Generic, General, Specific and Portable Bitwise Operations
First my apologies. My mental faculties currently leave rather a lot to be desired and I have thus spend an inordinate amount of time on this pet project of mine, testing myself if you will. I find it ...
5votes
1answer
117views
Instance specific code generation
Disclaimer: I've asked this question before on Stack overflow and got a response that this place would be a better fit so I am copy pasting the question here. I've come up with two different ...
12votes
4answers
3kviews
C generic dynamic array (using preprocessor)
I wrote a generic dynamic array using the preprocessor. My use case for it is a compiler I'm writing that uses dynamic arrays a lot, and my current void pointer implementation is becoming a bit hard ...
5votes
1answer
314views
C smart string implementation using preprocessor
I have wrote a smart string container implementation for use in my application, but as I'am not such professional C programmer I have doubts about is I'am did it right and is there ways how to improve ...
3votes
0answers
85views
Implement easy CLI options in C using a single-file header
I'm a computer science student, and in 2 of my courses this semester we are writing short C programs to demonstrate the things we are learning about. All of these programs require command-line flags &...
1vote
1answer
81views
c++ is it worth preprocessor optimization for for loops while i < 1 [closed]
I'm writing some code to take high precision timings of a function call ...
4votes
1answer
1kviews
Macro for counting number of elements in an array
We all know the classic version of counting the number of elements in a C array: sizeof(a)/sizeof(*a) But this is dangerous, because if used on a pointer it will ...