Last active
August 30, 2015 04:16
-
-
Save JonathonReinhart/e540ba61ae1a328a66a6 to your computer and use it in GitHub Desktop.
typedef provides no type safety
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 <stddef.h> | |
typedef size_t foo_h; | |
typedef size_t bar_h; | |
void foo(foo_h h) { (void)h; } | |
void bar(bar_h h) { (void)h; } | |
int main(void) | |
{ | |
foo_h f = 0; | |
foo(f); | |
bar(f); /* Wrong handle type! */ | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note that this compiles just fine, but will lead to serious trouble because the wrong "opaque pointer" was passed to
bar()
.