Can you use thread local variables inside a class or structure

后端 未结 9 1942
名媛妹妹
名媛妹妹 2020-12-30 23:34

Like this.

struct some_struct
{
 // Other fields
 .....
 __thread int tl;
}

I\'m trying to do that but the compiler is giving me this error

9条回答
  •  时光取名叫无心
    2020-12-31 00:24

    For C this makes not much sense, static (= global) members are only a feature of C++. And so the new C11 standard (that introduces _Thread_local) doesn't allow it. These beast are allowed basically everywhere were a variable with static storage duration is allowed.

    For C++ this could make sense inside a class as analogous to a static member, but if this is allowed by C++11 I have no idea.

提交回复
热议问题