Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #8443

Re: compile C programs for both sunstudio and Visual studio

From Keith Thompson <kst-u@mib.org>
Newsgroups comp.lang.c
Subject Re: compile C programs for both sunstudio and Visual studio
Date 2011-07-18 11:11 -0700
Organization None to speak of
Message-ID <lnwrffmpaq.fsf@nuthaus.mib.org> (permalink)
References <clcm-20110717-0005@plethora.net> <0.dac296d5b2e0c6dcc860.20110718123404BST.87ei1nesb7.fsf@bsb.me.uk>

Show all headers | View raw


Ben Bacarisse <ben.usenet@bsb.me.uk> writes:
[..]
> Almost all "console programs" run in a window (or maybe even real
> hardware) that understands ANSI control sequences.  If all you want to
> do is a few simple operations like clearing the screen, you could write
> short functions that produce the correct sequence.  For example,
>
>   void screen_clear(void) { puts("\x1b[H\x1b[2J"); }
>
> moves the cursor to the top of the screen and the clears it.

And then moves the cursor down one line.  puts() prints a '\n'
after printing its argument string.

Better:

    fputs("\x1b[H\x1b[2J", stdout);
    fflush(stdout);

Of course that's still non-portable, for various reasons that have
been discussed downthread.

But I suggest that the OP should ask himself whether he really
should be clearing the screen in the first place.

For a text editor or some other program that needs to take control
of the entire screen, clearing the screen is certainly a sensible
thing to do, but such a program is probably going to be using curses
or some similar package anyway.

For a program that just reads from stdin (assumed to be a keyboard)
and writes to stdout (assumed to be a screen of some sort),
clearing the screen can erase information that might be of some
value to the user.  Consider carefully whether your desire to have
a clean-looking display outweighs your user's desire to keep his
own information on the screen.  (Of course, if you're going to be
the only user of the program, do whatever you like.)

-- 
Keith Thompson (The_Other_Keith) kst-u@mib.org  <http://www.ghoti.net/~kst>
Nokia
"We must do something.  This is something.  Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

compile C programs for both sunstudio and Visual studio happytoday <ehabaziz2001@gmail.com> - 2011-07-17 22:49 -0500
  Re: compile C programs for both sunstudio and Visual studio Ben Bacarisse <ben.usenet@bsb.me.uk> - 2011-07-18 12:34 +0100
    Re: compile C programs for both sunstudio and Visual studio "Heinrich Wolf" <invalid@invalid.invalid> - 2011-07-18 15:34 +0200
      Re: compile C programs for both sunstudio and Visual studio Ben Bacarisse <ben.usenet@bsb.me.uk> - 2011-07-18 14:53 +0100
        Re: compile C programs for both sunstudio and Visual studio Virchanza <virtual@lavabit.com> - 2011-07-18 07:31 -0700
          Re: compile C programs for both sunstudio and Visual studio Ben Bacarisse <ben.usenet@bsb.me.uk> - 2011-07-18 15:38 +0100
            Re: compile C programs for both sunstudio and Visual studio Kenneth Brody <kenbrody@spamcop.net> - 2011-07-18 14:08 -0400
              Re: compile C programs for both sunstudio and Visual studio Ben Bacarisse <ben.usenet@bsb.me.uk> - 2011-07-18 19:18 +0100
      Re: compile C programs for both sunstudio and Visual studio Nobody <nobody@nowhere.com> - 2011-07-19 00:41 +0100
        Re: compile C programs for both sunstudio and Visual studio Ian Collins <ian-news@hotmail.com> - 2011-07-19 11:47 +1200
          Re: compile C programs for both sunstudio and Visual studio Keith Thompson <kst-u@mib.org> - 2011-07-18 19:08 -0700
            Re: compile C programs for both sunstudio and Visual studio Phil Carmody <thefatphil_demunged@yahoo.co.uk> - 2011-07-22 14:58 +0300
              Re: compile C programs for both sunstudio and Visual studio Keith Thompson <kst-u@mib.org> - 2011-07-22 09:42 -0700
                Re: compile C programs for both sunstudio and Visual studio Phil Carmody <thefatphil_demunged@yahoo.co.uk> - 2011-07-22 22:32 +0300
                Re: compile C programs for both sunstudio and Visual studio Keith Thompson <kst-u@mib.org> - 2011-07-22 13:16 -0700
          Re: compile C programs for both sunstudio and Visual studio Nobody <nobody@nowhere.com> - 2011-07-19 12:56 +0100
    Re: compile C programs for both sunstudio and Visual studio Kenneth Brody <kenbrody@spamcop.net> - 2011-07-18 14:06 -0400
    Re: compile C programs for both sunstudio and Visual studio Keith Thompson <kst-u@mib.org> - 2011-07-18 11:11 -0700
  Re: compile C programs for both sunstudio and Visual studio Geoff <geoff@invalid.invalid> - 2011-07-18 18:06 -0500
  Re: compile C programs for both sunstudio and Visual studio "Waldek M." <wm@localhost.localdomain> - 2011-07-18 18:07 -0500
  Re: compile C programs for both sunstudio and Visual studio BGB <cr88192@hotmail.com> - 2011-07-18 18:07 -0500
  Re: compile C programs for both sunstudio and Visual studio "io_x" <a@b.c.invalid> - 2011-07-19 17:40 -0500
    Re: compile C programs for both sunstudio and Visual studio "io_x" <a@b.c.invalid> - 2011-07-20 10:43 +0200
    Re: compile C programs for both sunstudio and Visual studio "io_x" <a@b.c.invalid> - 2011-07-30 01:48 -0500
    Re: compile C programs for both sunstudio and Visual studio Kenneth Brody <kenbrody@spamcop.net> - 2011-07-30 01:48 -0500
  Re: compile C programs for both sunstudio and Visual studio "io_x" <a@b.c.invalid> - 2011-07-19 17:40 -0500

csiph-web