Skip to content

Instantly share code, notes, and snippets.

@JonathonReinhart
Last active August 30, 2015 04:16
Show Gist options
  • Save JonathonReinhart/e540ba61ae1a328a66a6 to your computer and use it in GitHub Desktop.
Save JonathonReinhart/e540ba61ae1a328a66a6 to your computer and use it in GitHub Desktop.
typedef provides no type safety
#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;
}
@JonathonReinhart
Copy link
Author

Note that this compiles just fine, but will lead to serious trouble because the wrong "opaque pointer" was passed to bar().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment