All Questions
3
questions
3
votes
3
answers
167
views
How to check if a macro argument is an integer literal in C
I'm trying to do a macro like this:
#define STRING(i) \
struct STRING##i \
{ \
size_t len; \
char chars[i]; \
}
but the problem is this works with constexpr arguments like this:
constexpr int ...
1
vote
2
answers
96
views
Can __VA_OPT__(,) detect a trailing comma with nothing after it?
While playing with __VA_OPT__(,) I noticed the following behavior.
Background
First, note that C is fine with trailing commas in an initializer. These are equivalent:
int foo[] = { 10, 20, 30 };
int ...
2
votes
1
answer
350
views
Implementing std::bit_cast equivalent in C
Is it possible to implement something similar to C++20's std::bit_cast in C? It would be a lot more convenient than using union or casting pointers to different types and dereferencing.
If you had a ...