Thread: Jumping in the code...

  1. #16
    Registered User
    Join Date
    Sep 2008
    Posts
    20
    Quote Originally Posted by robwhit View Post
    Which editor are you using?
    Microsoft Visual C++ 6.0

  2. #17
    Registered User
    Join Date
    Sep 2008
    Posts
    20
    Quote Originally Posted by master5001 View Post
    system("cls"); Its insecure but about the only simple and portable way I can mention.
    Thanks again you really are the master!!!!!

  3. #18
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    cls isn't portable.

    To clear the text in a program, press Ctrl-A and then Del.

    http://faq.cprogramming.com/cgi-bin/...&id=1043284385

  4. #19
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Lol! Well I think I just heard matsp behind me with a vat of tar and a bag of feathers for telling people to use that particular command.

    Its only fair that I explain why some people will tell you not to use system(). The system() simply just calls processes shell commands. So if you say system("pause") it will execute the pause program. Or if you say system("notepad") then notepad will popup (or you could put system("gedit") for all you linux folk).

    The reason it is insecure is that it will just execute cls. Not necessarily the cls you want it to execute... just whichever one it finds in the current working directory or path variable. So someone could pull a fast one on you and throw a virus on your computer called "cls" and your program will officially be what starts that virus. 9 times out of 10 you end up with conflicts over malicious code, just FYI.

  5. #20
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    :S I use cls all the time on my linux box... did I make a link..........

  6. #21
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    AdampqmabA today you are officially inducted into the hall of "Don't program like that."

  7. #22
    The larch
    Join Date
    May 2006
    Posts
    3,573
    You can also jump around like this:

    Code:
    #include <iostream>
    #include <csetjmp>
    using namespace std;
    
    void jumping();
    
    jmp_buf jumper;
    
    int main(){
    
        cout << "hello";
        cout << "1";
        setjmp(jumper);
        cout << "2";
        if (std::cin.get()) {
            jumping();
        }
        return 0;
    }
    
    void jumping(){
        cout << "In jumping\n";
        longjmp(jumper, 1);
    }
    However, I doubt this is going to be useful in C++ code, since it wouldn't call any destructors when leaving the function.
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

  8. #23
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Nice. I can say that I have honestly never found an instance where I was able to produce more optimal code by using jumps. I am not so categorically against others using them. I don't use them very often myself. Its like a star screw-driver. Not a practical tool for most jobs, but when you need it, its a good thing to have handy.

  9. #24
    Registered User
    Join Date
    Sep 2008
    Posts
    20
    Quote Originally Posted by master5001 View Post
    AdampqmabA today you are officially inducted into the hall of "Don't program like that."
    I feel honoured!

  10. #25
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    I hope you caught anon's revelation about longjmp(). I didn't know that C supported long jumps. Now I know And knowing is half the battle!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Enforcing Machine Code Restrictions?
    By SMurf in forum Tech Board
    Replies: 21
    Last Post: 03-30-2009, 07:34 AM
  2. Values changing without reason?
    By subtled in forum C Programming
    Replies: 2
    Last Post: 04-19-2007, 10:20 AM
  3. Obfuscated Code Contest
    By Stack Overflow in forum Contests Board
    Replies: 51
    Last Post: 01-21-2005, 04:17 PM
  4. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM
  5. Replies: 0
    Last Post: 02-21-2002, 06:05 PM