Is it possible for a missing #include to break the program at runtime?

Antti_M :

Is there any case, where missing a #include would break the software at runtime, while the build still goes through?

In other words, is it possible that

#include "some/code.h"
complexLogic();
cleverAlgorithms();

and

complexLogic();
cleverAlgorithms();

would both build successfully, but behave differently?

john :

Yes, it's perfectly possible. I'm sure there are lots of ways, but suppose the include file contained a global variable definition which called a constructor. In the first case the constructor would execute, and in the second it wouldn't.

Putting a global variable definition in a header file is poor style, but it's possible.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=367730&siteId=1