Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Is there any way a C/C++ program can crash before main()?

Is there any way a C/C++ program can crash before main()?

Scheduled Pinned Locked Moved C / C++ / MFC
questionc++
8 Posts 6 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mbatra31
    wrote on last edited by
    #1

    Hi, I have one question... Is there any way a C/C++ program can crash before main()? Regards, Mbatra

    Y P L A V 5 Replies Last reply
    0
    • M mbatra31

      Hi, I have one question... Is there any way a C/C++ program can crash before main()? Regards, Mbatra

      Y Offline
      Y Offline
      yoaz
      wrote on last edited by
      #2

      The question is unclear: are you asking about compilation order?

      int x = ;
      int main()
      {
      return 0;
      }

      this will not compile, error is before main

      there are no facts, only interpretations

      M 1 Reply Last reply
      0
      • Y yoaz

        The question is unclear: are you asking about compilation order?

        int x = ;
        int main()
        {
        return 0;
        }

        this will not compile, error is before main

        there are no facts, only interpretations

        M Offline
        M Offline
        mbatra31
        wrote on last edited by
        #3

        Hi, My question was: Is there any way a C/C++ program can crash before main()? Like when u run your program, it crashes even before it starts to execute main.. Regards, Mbatra

        L 1 Reply Last reply
        0
        • M mbatra31

          Hi, My question was: Is there any way a C/C++ program can crash before main()? Like when u run your program, it crashes even before it starts to execute main.. Regards, Mbatra

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          Yes, it is possible, but without more details it is impossible to guess why.

          Use the best guess

          1 Reply Last reply
          0
          • M mbatra31

            Hi, I have one question... Is there any way a C/C++ program can crash before main()? Regards, Mbatra

            P Offline
            P Offline
            pasztorpisti
            wrote on last edited by
            #5

            The initialization of your static variables are performed before main() and their deinitialization is performed after main() returns or after the exit() call. If you put buggy code in there then you can easily crash before/after main().

            1 Reply Last reply
            0
            • M mbatra31

              Hi, I have one question... Is there any way a C/C++ program can crash before main()? Regards, Mbatra

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              Yes ! A c/c++ program will crash when it can't find a necessary library.

              1 Reply Last reply
              0
              • M mbatra31

                Hi, I have one question... Is there any way a C/C++ program can crash before main()? Regards, Mbatra

                A Offline
                A Offline
                Amarnath S
                wrote on last edited by
                #7

                Here is a cooked-up example:

                #include
                using namespace std;

                class Crash
                {
                public:
                Crash()
                {
                int *a = new int[5];
                for (int i = 0; i < 7; ++i)
                {
                a[i] = 25;
                }
                delete[] a;
                }
                };

                Crash crash;

                void main()
                {
                cout << "If ever I come here ..." << endl;
                }

                This program will crash even before entering main().

                1 Reply Last reply
                0
                • M mbatra31

                  Hi, I have one question... Is there any way a C/C++ program can crash before main()? Regards, Mbatra

                  V Offline
                  V Offline
                  Vijjuuu
                  wrote on last edited by
                  #8

                  Yes, it can if the program didn't find dependency libraries in the search paths.

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups