Questions tagged [c-preprocessor]
The c-preprocessor tag has no usage guidance.
12 questions
6
votes
3
answers
323
views
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,...
1
vote
0
answers
64
views
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 ...
1
vote
0
answers
53
views
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 ...
4
votes
1
answer
192
views
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):
...
7
votes
2
answers
721
views
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 ...
2
votes
0
answers
86
views
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 ...
5
votes
1
answer
115
views
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 ...
12
votes
4
answers
3k
views
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 ...
5
votes
1
answer
305
views
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 ...
3
votes
0
answers
81
views
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 &...
1
vote
1
answer
80
views
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
...
4
votes
1
answer
1k
views
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 ...