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. how to make this not stop?

how to make this not stop?

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialquestion
7 Posts 4 Posters 1 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.
  • U Offline
    U Offline
    User 7811724
    wrote on last edited by
    #1

    hey guys i have this

    int main(void)
    {
    while (malloc(50));
    return 0;
    }

    but after a couple of seconds it just asks to press any key to continue. what i would like it to do is just run till it crashes the program?

    K S E 3 Replies Last reply
    0
    • U User 7811724

      hey guys i have this

      int main(void)
      {
      while (malloc(50));
      return 0;
      }

      but after a couple of seconds it just asks to press any key to continue. what i would like it to do is just run till it crashes the program?

      K Offline
      K Offline
      krsmichael
      wrote on last edited by
      #2

      What environment?

      U 1 Reply Last reply
      0
      • K krsmichael

        What environment?

        U Offline
        U Offline
        User 7811724
        wrote on last edited by
        #3

        ? what do you mean.

        K 1 Reply Last reply
        0
        • U User 7811724

          ? what do you mean.

          K Offline
          K Offline
          krsmichael
          wrote on last edited by
          #4

          Wimdows, MacOSX, Linux, GCC, Visual Studio.....?

          U 1 Reply Last reply
          0
          • U User 7811724

            hey guys i have this

            int main(void)
            {
            while (malloc(50));
            return 0;
            }

            but after a couple of seconds it just asks to press any key to continue. what i would like it to do is just run till it crashes the program?

            S Offline
            S Offline
            Stephen Hewitt
            wrote on last edited by
            #5

            malloc returns NULL when it can't allocate the requested memory. So your program simply allocates 50 bytes in a loop until memory runs out then exits (as NULL is treated as false by the while loop). Why would you expect a spectacular crash?

            Steve

            1 Reply Last reply
            0
            • K krsmichael

              Wimdows, MacOSX, Linux, GCC, Visual Studio.....?

              U Offline
              U Offline
              User 7811724
              wrote on last edited by
              #6

              windows, using c-free 5. i just want it to keep running untill it crashes or slows my comp down heaps

              1 Reply Last reply
              0
              • U User 7811724

                hey guys i have this

                int main(void)
                {
                while (malloc(50));
                return 0;
                }

                but after a couple of seconds it just asks to press any key to continue. what i would like it to do is just run till it crashes the program?

                E Offline
                E Offline
                Emilio Garavaglia
                wrote on last edited by
                #7

                int main()
                {
                while(true)
                malloc(50);
                return 0;
                }

                The loop is now infinite, but the memory will sooner or later be exhausted. At that point, malloc will not allocate anymore, but the loop will still cycle forever. It will be very hard to stop it, having no more resource to create another process to kill the cycling one ...

                2 bugs found. > recompile ... 65534 bugs found. :doh:

                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