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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. How to crash my programe before main()?

How to crash my programe before main()?

Scheduled Pinned Locked Moved C / C++ / MFC
questionc++tutorial
17 Posts 8 Posters 4 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.
  • A Anilkumar K V

    create any gloabl object, in ur program. put some code to crash in its constructor Kill before even born....Its is called abortion!!!:laugh: -- modified at 7:14 Wednesday 11th January, 2006

    V Offline
    V Offline
    vikas amin
    wrote on last edited by
    #7

    What about C ??? this is c++:cool: Vikas Amin Embin Technology Bombay

    1 Reply Last reply
    0
    • L lemur2

      Of the top of my head, can't think of a way in C, but in C++ you can simply use some form of static initialiser. Be warned though, that they can cause problems if not handled correctly. I'd recommend asking yourself if you really need to do this? Kev

      V Offline
      V Offline
      vikas amin
      wrote on last edited by
      #8

      Pls elaborate "Static initialiser ". Small code can be of help. Vikas Amin Embin Technology Bombay

      1 Reply Last reply
      0
      • R Rajesh R Subramanian

        1. Get yourself a sledge hammer 2. Take a deep breath 3. Swing the hammer back and give the program (The display, where it is being shown) a merciless blow. 4. The program should have crashed by now. :D This is a code sample #include using namespace std; class GoGoGo { public: GoGoGo() { cout << "This runs first!"; //put ur code to crash the program here.. } BeFirst; } int main() { cout << "Main is second :("; return 0; } Google for interview questions and u will find a lot of stuff. I learned this from google some months back. Regards, Rajesh R. Subramanian You have an apple and me too. We exchange those and We have an apple each. You have an idea and me too. We exchange those and We have two ideas each.

        L Offline
        L Offline
        lemur2
        wrote on last edited by
        #9

        You need to declare an instance of class GoGoGo before this will work - i.e.: GoGoGo executesBeforeMain; Kev

        S 1 Reply Last reply
        0
        • V vikas amin

          Ok very popular question how do i crash my programe before reaching main. I dont actually want to crash the programe but want to know how can i execute a piece of code before main is executed . Consider C and C++ only Answer shoud be compiler independent :cool: Vikas Amin Embin Technology Bombay

          C Offline
          C Offline
          Cedric Moonen
          wrote on last edited by
          #10

          int CrashingFunc(); static int SomeIntThatCrashesTheProg = CrashingFunc(); int CrashingFunc() { // Put crashing code here } The static variables will be evaluated first and this will call your CrashingFunc before the main()

          S 1 Reply Last reply
          0
          • C Cedric Moonen

            int CrashingFunc(); static int SomeIntThatCrashesTheProg = CrashingFunc(); int CrashingFunc() { // Put crashing code here } The static variables will be evaluated first and this will call your CrashingFunc before the main()

            S Offline
            S Offline
            sunit5
            wrote on last edited by
            #11

            is it neccesary to put static . static int SomeIntThatCrashesTheProg = CrashingFunc(); int CrashingFunc() I feel int SomeIntThatCrashesTheProg has to be Global which u have defined with static never say die -- modified at 9:27 Wednesday 11th January, 2006

            V 1 Reply Last reply
            0
            • L lemur2

              You need to declare an instance of class GoGoGo before this will work - i.e.: GoGoGo executesBeforeMain; Kev

              S Offline
              S Offline
              sunit5
              wrote on last edited by
              #12

              It has to be class GoGoGo { public: GoGoGo() { cout << "This runs first!"; //put ur code to crash the program here.. } }BeFirst; never say die

              R 1 Reply Last reply
              0
              • V vikas amin

                Ok very popular question how do i crash my programe before reaching main. I dont actually want to crash the programe but want to know how can i execute a piece of code before main is executed . Consider C and C++ only Answer shoud be compiler independent :cool: Vikas Amin Embin Technology Bombay

                V Offline
                V Offline
                vipinasda
                wrote on last edited by
                #13

                Why do you want to do so? Can you tell the usability? Vipin - MVP

                V 1 Reply Last reply
                0
                • V vipinasda

                  Why do you want to do so? Can you tell the usability? Vipin - MVP

                  V Offline
                  V Offline
                  vikas amin
                  wrote on last edited by
                  #14

                  Actually i dont want to crash the program but i am studying the reason by which the programs can crash before the main function is exectuted Vikas Amin Embin Technology Bombay

                  R 1 Reply Last reply
                  0
                  • S sunit5

                    is it neccesary to put static . static int SomeIntThatCrashesTheProg = CrashingFunc(); int CrashingFunc() I feel int SomeIntThatCrashesTheProg has to be Global which u have defined with static never say die -- modified at 9:27 Wednesday 11th January, 2006

                    V Offline
                    V Offline
                    vikas amin
                    wrote on last edited by
                    #15

                    yeh globals if they are initalised then they can crash the prog . :-O Vikas Amin Embin Technology Bombay

                    1 Reply Last reply
                    0
                    • S sunit5

                      It has to be class GoGoGo { public: GoGoGo() { cout << "This runs first!"; //put ur code to crash the program here.. } }BeFirst; never say die

                      R Offline
                      R Offline
                      Rajesh R Subramanian
                      wrote on last edited by
                      #16

                      Sorry abt that. Din notice it. You have an apple and me too. We exchange those and We have an apple each. You have an idea and me too. We exchange those and We have two ideas each.

                      1 Reply Last reply
                      0
                      • V vikas amin

                        Actually i dont want to crash the program but i am studying the reason by which the programs can crash before the main function is exectuted Vikas Amin Embin Technology Bombay

                        R Offline
                        R Offline
                        Rajesh R Subramanian
                        wrote on last edited by
                        #17

                        vikas amin wrote:

                        i am studying the reason by which the programs can crash before the main function is exectuted

                        If so, you will do a never ending study. Atleast after you start with windows programming. (If you ever finish studying this with C and C++) :D Why do this dude? Destructive mind huh? X| Regards, Rajesh R. Subramanian You have an apple and me too. We exchange those and We have an apple each. You have an idea and me too. We exchange those and We have two ideas each.

                        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