dimanche 23 août 2015

local static/thread_local variables of inline functions?

If I have a static local variable or thread_local local variable that is within an inline function that is defined in different translation units, in the final program are they gauranteed by the standard to have the same address?

TU1:
inline int* f() { static int x; return &x; }
extern int* a;
void sa() { a = f(); }

TU2:
inline int* f() { static int x; return &x; }
extern int* b;
void sb() { b = f(); }

TU3:
int *a, *b;
void sa();
void sb();
int main() { sa(); sb(); return a == b; }

Will the above always return 1?

Aucun commentaire:

Enregistrer un commentaire