Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c++

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?

like image 435
Antti_M Avatar asked Mar 20 '20 09:03

Antti_M


People also ask

Is it possible to get sick when you miss someone?

Love can't give you the flu. But the hormone fluctuations associated with love and heartbreak — particularly the stress hormone cortisol — can prompt physical symptoms that affect your long-term health. Lovesickness can also make you sick indirectly.

Is it possible to miss someone so much it hurts?

Missing someone hurts. The ache of yearning for another person can cause you to experience sadness, emptiness, despair, or a deep sense of absence. Most people understand that these feelings are normal following the loss of a loved one or when a close friend moves away.

How do I know if I am missing someone?

Signs That You're Missing SomeoneExperiencing a sense of longing. Eating more or less than you normally do. Feeling lovesick. Feeling lonely or isolated.

What happens psychologically when you miss someone?

The feeling you get when you miss your partner means that your brain is seeking them out and typically your oxytocin and dopamine levels drop. As Tara L. Skubella, relationship expert and tantra coach with Earth Tantra, tells Bustle, "Physical touch, sexual and heartfelt connection increases these levels.


2 Answers

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.

like image 133
john Avatar answered Sep 28 '22 03:09

john


Yes, that's possible.

Everything concerning #includes happens at compile time. But compile time things can change behavior at runtime, of course:

some/code.h:

#define FOO int foo(int a) { return 1; } 

then

#include <iostream> int foo(float a) { return 2; }  #include "some/code.h"  // Remove that line  int main() {   std::cout << foo(1) << std::endl;   #ifdef FOO     std::cout << "FOO" std::endl;   #endif } 

With the #include, overload resolution finds the more appropriate foo(int) and hence prints 1 instead of 2. Also, since FOO is defined, it additionally prints FOO.

That's just two (unrelated) examples that came to my mind immediately, and I'm sure there are plenty more.

like image 25
pasbi Avatar answered Sep 28 '22 03:09

pasbi