Created
June 12, 2019 11:27
-
-
Save nyrahul/242b705eb9fdbb2ab4349a3aa6685343 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// Example code which shows how to compare the two typedefs for size equivalency. | |
#define CONCAT_(a,b) a##b | |
#define CONCAT(a,b) CONCAT_(a, b) | |
#define STATIC_ASSERT(e) \ | |
; enum { CONCAT(assert_line_, __LINE__) = 1/(int)(!!(e)) } | |
/* Note that ; is needed before enum if the STATIC_ASSERT is added right after case or label statement */ | |
/* Note that multiple CONCATs are needed so that __LINE__ could be expanded .. Thus you can now have multiple STATIC_ASSERTs in the same code block */ | |
typedef int uniqid_t; | |
typedef short mnid_t; | |
STATIC_ASSERT(sizeof(mnid_t) <= sizeof(uniqid_t)); | |
int main(void) | |
{ | |
int t = 1; | |
switch(t) | |
{ | |
case 0: | |
STATIC_ASSERT(sizeof(mnid_t) <= sizeof(int)); | |
break; | |
default: | |
break; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment