|
|
|
|
|
by AnimalMuppet
3126 days ago
|
|
An embedded system written in C++ had a Singleton. The Singleton pattern means that you have one instance, which has to live somewhere. This implementation had the instance as a static variable in the getInstance() method, e.g.: Foo* getInstance()
{
static Foo;
return foo;
}
This is perfectly valid.Unfortunately, getInstance() was implemented in Foo.h, not in Foo.cpp. But in C++, functions in header files are inline by default. This means that every caller of Foo::getInstance() wound up with their own "static Foo" in their own inlined Foo::getInstance(), which meant that each caller got a different instance of the Singleton. Most interesting bug I've seen in ten years. |
|