hedley
hedley copied to clipboard
Add HEDLEY_TYPEOF
I was pointed to your project from StackOverflow (commenter says you're his "fav project" 😄) as I was looking for well-tested preprocessor detection of __typeof
.
https://stackoverflow.com/questions/73848714/detect-if-a-c-compiler-supports-typeof-and-or-decltype
I see you started working on __typeof
support a few years ago, but never committed it to trunk:
https://github.com/nemequ/hedley/commit/9c3e8420cdb1ce1f89fcf70f07281e92df176f98#diff-b01d6052731bb4f6e3cf6dfb281442574769d119caa48f61a422e05f9b540f8a
Some caveats:
- In C,
int i; __typeof((i))
isint
. In C++,decltype(i)
isint
butdecltype((i))
isint&
. Therefore, you'd either have to document that the C++ version must be used only on identifiers, or (better?) you'd have to#define HEDLEY_TYPEOF(...) typename std::remove_ref<decltype(__VA_ARGS__)>::type
. - In GCC and Clang and EDG and also in C23 if I understand correctly,
const int ci = 1; __typeof(ci)
isconst int
, i.e.,__typeof
does not strip cv-qualifiers. On ChibiCC,__typeof__(ci)
isint
. - I noticed that ChibiCC supports
__typeof__
but not__typeof
. Most compilers support both. - I noticed that VBCC "supports"
__typeof(x)
, but it's a builtin that returns anint
value (1=char, 3=int, 6=float, etc.) instead of the GNU C version that yields a typename.