-1

Does std::atomic<basic_type> guarantee the value of basic_type to be 0 / 0.0 (whichever is applicable) when created as a class member without being explicitely initialized for:

  • int / uint / short / ushort / etc...
  • and; float / double

?

Example:

class Foo
{
public:
    std::atomic<int> bar;
};

int main()
{
    Foo foo;
    return foo.bar; //foo.bar guaranteed to be 0?
}
Gizmo
  • 1,990
  • 1
  • 24
  • 50
  • I assume you have read [the fine manual](http://en.cppreference.com/w/cpp/atomic/atomic/atomic) and found it lacking. Is there some part of `no initialization takes place other than zero initialization of static and thread-local objects` that you find unclear? Basically, `std::atomic bar` provides the same (few) guarantees of the initial value as `int bar` would. – Igor Tandetnik Apr 15 '16 at 04:49

1 Answers1

1

from cppreference documentation of std::atomic default constructor:

The default constructor is trivial: no initialization takes place other than zero initialization of static and thread-local objects. std::atomic_init may be used to complete initialization.

Hence in your case you will have the same guarantees as if you had declared simply int bar;

Stefano
  • 3,981
  • 8
  • 36
  • 66