Skip to content

Instantly share code, notes, and snippets.

@vathpela
Created May 29, 2021 18:10
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 vathpela/9692dbd5eeae0f796831d0b7a498779a to your computer and use it in GitHub Desktop.
Save vathpela/9692dbd5eeae0f796831d0b7a498779a to your computer and use it in GitHub Desktop.
is-const tester
#include <stdbool.h>
#include <stdio.h>
#define is_const(a) \
_Generic((a), \
const typeof(a): true, \
default: false)
int
main(void)
{
const int a = 0;
int b = 0;
if (is_const(a))
printf("a is const\n");
if (is_const(b))
printf("b is const\n");
return 0;
}
// vim:fenc=utf-8:tw=75:noet
random:~/devel/local/test$ gcc -Og -std=gnu2x -Wall -Wextra -Werror -o is-const is-const.c
random:~/devel/local/test$ ./is-const
random:~/devel/local/test$
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment