Created
May 29, 2021 18:10
-
-
Save vathpela/9692dbd5eeae0f796831d0b7a498779a to your computer and use it in GitHub Desktop.
is-const tester
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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