Skip to content

Instantly share code, notes, and snippets.

@tjw
Created January 10, 2013 06:23
Show Gist options
  • Save tjw/4499886 to your computer and use it in GitHub Desktop.
Save tjw/4499886 to your computer and use it in GitHub Desktop.
#import <stdio.h>
#define UNIQUE_CONST_PTR2(X) ({ static unsigned X; &X; })
#define CAT(x,y) x##y
#define UNIQUE_CONST_PTR1(X, Y) UNIQUE_CONST_PTR2(CAT(X,Y))
#define UNIQUE_CONST_PTR(KEY) UNIQUE_CONST_PTR1(KEY, __COUNTER__)
int main(int argc, char *argv[])
{
const void *u1 = UNIQUE_CONST_PTR(A);
const void *u2 = UNIQUE_CONST_PTR(A);
printf("u1 = %p\n", u1);
printf("u2 = %p\n", u2);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment