The exact thing you asked for cannot be done using only standard language tools, but some compilers have extensions that let you do this. For example, with GCC, this can do what you want ( here>).
#define ASMNAME(x) ASMNAME_(__USER_LABEL_PREFIX__, #x)
#define ASMNAME_(x,y) ASMNAME__(x, y)
#define ASMNAME__(x,y) __asm__(#x y)
int x;
extern int y ASMNAME(x);
int main(void)
{
return !(&x == &y);
}
Notice what effect this has, though: there is only one variable in the object file, and its name x. ywas declared as another name for it in the source code. This may or may not be good enough depending on what you are trying to do.
, . :
#define ASMNAME(x) ASMNAME_(__USER_LABEL_PREFIX__, #x)
#define ASMNAME_(x,y) ASMNAME__(x, y)
#define ASMNAME__(x,y) __asm__(#x y)
int x;
extern int y ASMNAME(x);
#include <stdio.h>
int main(void)
{
int a, b;
x = 1;
a = x;
y = 2;
b = x;
printf("a=%d b=%d x=%d y=%d\n", a, b, x, y);
return 0;
}
a=1 b=1 x=1 y=2
y x.