Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The simple answer is: <strong>Yes</strong>.</p> <p>More specifically, we can differentiate between two causes for this. I'll call them <strong>implementation-dependent</strong> and <strong>implementation-independent</strong>.</p> <p><strong>The one case that doesn't depend on your environment at all</strong> is that of static objects in C++, which was mentioned here. The following code dies before <code>main()</code>:</p> <pre><code>#include &lt;iostream&gt; class Useless { public: Useless() { throw "You can't construct me!"; } }; static Useless object; int main() { std::cout &lt;&lt; "This will never be printed" &lt;&lt; std::endl; return 0; } </code></pre> <p>More interesting are the <strong>platform-dependent causes</strong>. Some were mentioned here. One that was mentioned here a couple of times was the usage of dynamically linked libraries (DLLs in windows, SOs in Linux, etc.) - if your OS's loader loads them before <code>main()</code>, they might cause your application do die before <code>main()</code>.</p> <p>A more general version of this cause is talking about all the things <strong>your binary's entry point</strong> does before calling <strong>your</strong> entry point(<code>main()</code>). Usually when you build your binary there's a pretty serious block of code that's called when your operating system's loader starts to run your binary, and when it's done it calls your <code>main()</code>. One common thing this code does is initializing the C/C++ standard library. This code can fail for any number of reasons (shortage of any kind of system resource it tries to allocate for one).</p> <p>One interesting way on for a binary to execute code before <code>main()</code> on windows is using TLS callbacks (google will tell you more about them). This technique is usually found in malware as a basic anti-debugging trick (this trick used to fool ollydbg back then, don't know if it still does).</p> <p>The point is that your question is actually equivalent to "is there a way that loading a binary would cause user code to execute before the code in <code>main()</code>?", and the answer is <strong>hell, yeah!</strong></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload