You might be able to tell static and local variables apart by using their addresses:
For example the output of the following program on my system
#include <stdio.h>
void f0() {
int x = 0;
printf("%p\n", &x);
}
void f1() {
static int x = 0;
printf("%p\n", &x);
}
int main() {
f0();
f1();
return 0;
}
is this:
0x7fff1dc718dc
0x600900
Where each section and the stack are placed depends on the ABI of your platform, but you could use the address of a block-local variable to form a condition:
#include <stdio.h>
#define check(var) { \
int ___ = 0; \
printf("%s (%p): %s\n", #var, &var, (&var > &___)?"local":"static"); \
}
void f0() {
int x = 0;
check(x);
}
void f1() {
static int y = 0;
check(y);
}
int main() {
f0();
f1();
return 0;
}
This outputs:
x (0x7fff4b965afc): local
y (0x600978): static
Warning: I would not advise using this "trick". That's all it is: a trick, one that will break in the most unopportune of circumstances. Just document your macro properly and let the people who use it handle the aftermath of its misuse.