Skip to content

Instantly share code, notes, and snippets.

Created October 12, 2012 10:24
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 anonymous/3878585 to your computer and use it in GitHub Desktop.
Save anonymous/3878585 to your computer and use it in GitHub Desktop.
stdin
void *av_x_if_null(const void *x, const void *y)
{
return (void *) (x ? x : y);
}
#define WARN_IF_TYPES_DIFFER(x,y) ((void) sizeof(x == y))
#define av_x_if_null_warn(x,y) \
( \
WARN_IF_TYPES_DIFFER(x, y), \
av_x_if_null(x, y) \
)
int main(void)
{
int *a = 0;
char *b = 0;
int *i = av_x_if_null_warn(a, a); // fine
short *c = av_x_if_null_warn(i, b);
return c ? 1 : 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment