View Poll Results: Who agrees with me that this thread should die?

Voters
5694. You may not vote on this poll
  • Should die now

    5,694 100.00%
  • Should let message board nature take it down the list

    0 0%

Thread: Clearing the console

  1. #1
    Registered User
    Join Date
    Sep 2005
    Location
    USA
    Posts
    69

    Question Clearing the console

    Hi, is there any way I can erase the contents of the console?
    Thanks,
    Adam

  2. #2
    C/C++Newbie Antigloss's Avatar
    Join Date
    May 2005
    Posts
    216
    Code:
    for ( int i = 0; i < 50; ++i ) {
          putchar('\n');
    }

  3. #3
    *this
    Join Date
    Mar 2005
    Posts
    498
    Acutally IMHO thats not a very good way to clear the console. For one, it moves the cursor to the bottom, and for two you dont know the size of the console window.

    Check out http://faq.cprogramming.com

    This has been asked a BAziiilliiioooon times, search the faq and the boards you will find many ways, many arguments, many fights, and many other things about clearing the screen.

  4. #4
    Registered User
    Join Date
    Sep 2005
    Location
    USA
    Posts
    69
    Thanks
    Adam

  5. #5
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,829
    It's covered, along with a load of other stuff, in part 2 of my console programming tutorial.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  6. #6
    Software engineer
    Join Date
    Aug 2005
    Location
    Oregon
    Posts
    283
    Quote Originally Posted by Antigloss
    Code:
    for ( int i = 0; i < 50; ++i ) {
          putchar('\n');
    }
    For speed purposes, do the following:

    for (register int i = 0; i < 50; ++i ) {
    putchar('\n');
    }

    The loop control variable is saved as a register in the computer instead of memory, so accessing it will be much more efficient. For today's computers, it's probably not going to be a difference, but you don't know what computer your users will have. Regardless, it's still theoretically faster accessing a register than accessing memory.

  7. #7
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    Rare is the compiler that's not smart enough to put a loop variable into a register. In fact, a loop with fixed run length will be either unrolled (though 50 iterations might be too many for that), or implemented using the x86 LOOP instruction, which requires the counter to be in the ECX register.

    Most modern compilers are, in most situations, better off deciding for themselves which variables go into registers.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  8. #8
    Software engineer
    Join Date
    Aug 2005
    Location
    Oregon
    Posts
    283
    Stupid compilers... they think they're so smart...

  9. #9
    Registered User
    Join Date
    Aug 2005
    Posts
    1,267
    Microsoft 32-bit compilers ignore the register keyword. I suppose other compiler do too.

  10. #10
    Software engineer
    Join Date
    Aug 2005
    Location
    Oregon
    Posts
    283
    Eitehr way, I think it's a good habit to get into, because there's so many systems out in the world that depend on C/C++ code.

    According to Microsoft:
    The compiler does not honor user requests for register variables; instead, it makes its own register choices when global optimizations are on.
    Last edited by dxfoo; 09-07-2005 at 11:02 AM.

  11. #11
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    I still disagree. The register keyword makes a low-level optimization choice that you shouldn't make until profiling actually shows that there's significant time lost.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  12. #12
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > Eitehr way, I think it's a good habit to get into
    ROFLMAO - I seriously doubt you'll find a serious compiler which can't do this.
    If you do, you've got other problems to think about.

    Such twee micro-optimisations are really a waste of effort nowadays. For a start, you have no idea how many registers are on the current machine (yes, I'm talking about the real world, not the insulated world of wintel).

    Besides, you fail to take into account the work inside the loop (lots - I/O is expensive) with the work of the loop itself (almost nothing).

    Consider the possibility that the compiler decides to follow your guess as opposed to what it knows is the real register usage, and as a result generates WORSE code than what it would have generated had you not said anything.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  13. #13
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    ... that's another way to say it ...
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  14. #14
    Registered User
    Join Date
    Sep 2005
    Location
    USA
    Posts
    69
    Does anyone know where I can download curses.h?
    Adam

  15. #15
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    Well, you can get ncurses here:
    http://www.gnu.org/software/ncurses/ncurses.html
    It's UNIX-only, though.

    Public Domain Curses looks more promising for Windows:
    http://sourceforge.net/projects/pdcurses
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Full Screen Console
    By St0rmTroop3er in forum C++ Programming
    Replies: 1
    Last Post: 09-26-2005, 09:59 PM
  2. Console Functions Help
    By Artist_of_dream in forum C++ Programming
    Replies: 9
    Last Post: 12-04-2004, 03:44 AM
  3. Clearing the screen in a dos console window...
    By Unregistered in forum C++ Programming
    Replies: 13
    Last Post: 02-15-2002, 04:15 AM
  4. Just one Question?
    By Irish-Slasher in forum C++ Programming
    Replies: 6
    Last Post: 02-12-2002, 10:19 AM
  5. clearing an NT console
    By iain in forum C++ Programming
    Replies: 1
    Last Post: 12-07-2001, 01:08 PM