Skip to content

Instantly share code, notes, and snippets.

@imaami
Last active April 15, 2023 13:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save imaami/228f8f02bfc6e2576bbf8970b794a061 to your computer and use it in GitHub Desktop.
Save imaami/228f8f02bfc6e2576bbf8970b794a061 to your computer and use it in GitHub Desktop.
Backport of C23's typeof_unqual using GNU extensions
/* If you compile with clang and `-Weverything' you'll probably want
* to use `-Wno-gnu-statement-expression-from-macro-expansion', too.
*
* Plain C18 version:
* https://gist.github.com/imaami/92b38f45142f8a8390fefa2d972bc63d
*/
#define typeof_unqual(x) __typeof__(({ *(__typeof__(x) *)(void *)0; }))
int main(void)
{
const int ci = 1;
typeof_unqual(ci) i1 = ci;
typeof_unqual(const int) i2 = ci;
i1 = 0;
i2 = 0;
return i1 + i2;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment