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


Groups > comp.lang.c > #8404 > unrolled thread

compile C programs for both sunstudio and Visual studio

Started byhappytoday <ehabaziz2001@gmail.com>
First post2011-07-17 22:49 -0500
Last post2011-07-19 17:40 -0500
Articles 20 on this page of 26 — 13 participants

Back to article view | Back to comp.lang.c


Contents

  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

Page 1 of 2  [1] 2  Next page →


#8404 — compile C programs for both sunstudio and Visual studio

Fromhappytoday <ehabaziz2001@gmail.com>
Date2011-07-17 22:49 -0500
Subjectcompile C programs for both sunstudio and Visual studio
Message-ID<clcm-20110717-0005@plethora.net>
I comile C programs for bothe platforms : sunstudio using cc , visual
studio 6 . Is there a command to differeniate which platform I compile
for . That in order to use the the system command .

For example :

If (unixplatform)
system("clear");
else
system("cls")
-- 
comp.lang.c.moderated - moderation address: clcm@plethora.net -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line.  Sorry.

[toc] | [next] | [standalone]


#8423

FromBen Bacarisse <ben.usenet@bsb.me.uk>
Date2011-07-18 12:34 +0100
Message-ID<0.dac296d5b2e0c6dcc860.20110718123404BST.87ei1nesb7.fsf@bsb.me.uk>
In reply to#8404
happytoday <ehabaziz2001@gmail.com> writes:

> I comile C programs for bothe platforms : sunstudio using cc , visual
> studio 6 . Is there a command to differeniate which platform I compile
> for . That in order to use the the system command .
>
> For example :
>
> If (unixplatform)
> system("clear");
> else
> system("cls")

Every compiler defines one or more macros that can be used to determine
when you are using it.  Check the documentation, but I think Sun
compilers define __sun so you can write:

  #ifdef __sun
    system("clear);
  #else
    system("cls");
  #endif

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.

Even if you decide to use conditional compilation, it's a good idea to
put all such system dependencies into functions that are defined away
from the rest of the code:

  void screen_clear(void)
  {
  #ifdef __sun
    system("clear);
  #else
    system("cls");
  #endif
  }

-- 
Ben.

[toc] | [prev] | [next] | [standalone]


#8428

From"Heinrich Wolf" <invalid@invalid.invalid>
Date2011-07-18 15:34 +0200
Message-ID<j01coc$ufi$1@news.m-online.net>
In reply to#8423
"Ben Bacarisse" <ben.usenet@bsb.me.uk> schrieb im Newsbeitrag 
news:0.dac296d5b2e0c6dcc860.20110718123404BST.87ei1nesb7.fsf@bsb.me.uk...
...
> 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.
...
The windows console does not natively understand ANSI control sequences. You 
would explicitely have to load the ANSI driver. And I was told not to use 
hardcoded ANSI control sequences on Unix either.

my code for clearing the screen is the following (working with Turbo C 2.0, 
Borland C++Builder 5, MSVC, Linux, SCO Unix, SINIX). clear() is defined on 
Unix in curses.h . clrscr() is defined on Turbo C in conio.h , but on 
Borland C++Builder clrscr() does not clear more then 44 lines (a Windows 
console may have more).

#if        defined(sinix) || defined(SNI) || defined(M_UNIX) || 
defined(linux)
  #define  Unix
#endif

#ifdef     Unix
  #include <termios.h>
  #include <curses.h>
#else
  #include <conio.h>
#endif

#ifdef     __TURBOC__
  #if      __TURBOC__    <= 0x0200
    #define clear           clrscr
  #else
    #define ReplaceConio
    #include <windows.h>
  #endif
#endif

#ifdef     MSDOS
  #define  clear()          _clearscreen(_GCLEARSCREEN)
#endif

#ifdef     _MSC_VER
  #define  ReplaceConio
  #include <windows.h>
  #include <wincon.h>
#endif

#ifdef     ReplaceConio
  void clear(void)
    {
    COORD                      coordScreen;
    DWORD                      cCharsWritten,
                               dwConSize;
    HANDLE                     hConsole;
    CONSOLE_SCREEN_BUFFER_INFO csbi;

    coordScreen.X = 0;
    coordScreen.Y = 0;
    hConsole      = GetStdHandle(STD_OUTPUT_HANDLE);
    GetConsoleScreenBufferInfo(hConsole, &csbi);
    dwConSize     = csbi.dwSize.X * csbi.dwSize.Y;
    FillConsoleOutputCharacter(hConsole, ' ', dwConSize,
                               coordScreen, &cCharsWritten);
    FillConsoleOutputAttribute(hConsole, csbi.wAttributes,
                               dwConSize, coordScreen,
                               &cCharsWritten);
    SetConsoleCursorPosition(
      GetStdHandle(STD_OUTPUT_HANDLE), coordScreen);
    }
#endif

[toc] | [prev] | [next] | [standalone]


#8430

FromBen Bacarisse <ben.usenet@bsb.me.uk>
Date2011-07-18 14:53 +0100
Message-ID<0.82efe6f52f99647d6db3.20110718145314BST.87vcuzd7at.fsf@bsb.me.uk>
In reply to#8428
"Heinrich Wolf" <invalid@invalid.invalid> writes:

> "Ben Bacarisse" <ben.usenet@bsb.me.uk> schrieb im Newsbeitrag
> news:0.dac296d5b2e0c6dcc860.20110718123404BST.87ei1nesb7.fsf@bsb.me.uk...
> ...
>> 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.
> ...
> The windows console does not natively understand ANSI control
> sequences. You would explicitely have to load the ANSI driver.

You are quite right -- I'd forgotten that.

> And I
> was told not to use hardcoded ANSI control sequences on Unix either.

Also true (and very much so when I started out) but there are ever fewer
cases where simple ANSI sequences won't work.  It's just possible that
with a generous reading of "almost all" and a few corrupt statisticians
in my employ I could still justify my original statement, but I should
give it up!

As your code shows, there is no simple portable solution.

<snip>
-- 
Ben.

[toc] | [prev] | [next] | [standalone]


#8431

FromVirchanza <virtual@lavabit.com>
Date2011-07-18 07:31 -0700
Message-ID<9a8ae97c-ce9d-497d-86e8-bb094a9a8c0f@p14g2000yqj.googlegroups.com>
In reply to#8430
On Jul 18, 2:53 pm, Ben Bacarisse <ben.use...@bsb.me.uk> wrote:

> As your code shows, there is no simple portable solution.

I went all-out with a program of a mine and used the cross-platform
"ncurses" library:

http://en.wikipedia.org/wiki/Ncurses

[toc] | [prev] | [next] | [standalone]


#8432

FromBen Bacarisse <ben.usenet@bsb.me.uk>
Date2011-07-18 15:38 +0100
Message-ID<0.d085c796a144120c3875.20110718153859BST.87pql7d56k.fsf@bsb.me.uk>
In reply to#8431
Virchanza <virtual@lavabit.com> writes:

> On Jul 18, 2:53 pm, Ben Bacarisse <ben.use...@bsb.me.uk> wrote:
>
>> As your code shows, there is no simple portable solution.
>
> I went all-out with a program of a mine and used the cross-platform
> "ncurses" library:
>
> http://en.wikipedia.org/wiki/Ncurses

How much functionality does ncurses give you on a Windows console when
there is no ANSI driver loaded?

-- 
Ben.

[toc] | [prev] | [next] | [standalone]


#8442

FromKenneth Brody <kenbrody@spamcop.net>
Date2011-07-18 14:08 -0400
Message-ID<76adnf1b4es-67nTnZ2dnUVZ_jCdnZ2d@bestweb.net>
In reply to#8432
On 7/18/2011 10:38 AM, Ben Bacarisse wrote:
> Virchanza<virtual@lavabit.com>  writes:
>
>> On Jul 18, 2:53 pm, Ben Bacarisse<ben.use...@bsb.me.uk>  wrote:
>>
>>> As your code shows, there is no simple portable solution.
>>
>> I went all-out with a program of a mine and used the cross-platform
>> "ncurses" library:
>>
>> http://en.wikipedia.org/wiki/Ncurses
>
> How much functionality does ncurses give you on a Windows console when
> there is no ANSI driver loaded?

I can't say, not having touched ncurses for years.  However, I can tell you 
that there is no need for any ANSI driver, as there is an entire Windows 
Console API available to handle such things.

-- 
Kenneth Brody

[toc] | [prev] | [next] | [standalone]


#8446

FromBen Bacarisse <ben.usenet@bsb.me.uk>
Date2011-07-18 19:18 +0100
Message-ID<0.9d81970aed8fb74f80f4.20110718191823BST.878vrvcv0w.fsf@bsb.me.uk>
In reply to#8442
Kenneth Brody <kenbrody@spamcop.net> writes:

> On 7/18/2011 10:38 AM, Ben Bacarisse wrote:
>> Virchanza<virtual@lavabit.com>  writes:
>>
>>> On Jul 18, 2:53 pm, Ben Bacarisse<ben.use...@bsb.me.uk>  wrote:
>>>
>>>> As your code shows, there is no simple portable solution.
>>>
>>> I went all-out with a program of a mine and used the cross-platform
>>> "ncurses" library:
>>>
>>> http://en.wikipedia.org/wiki/Ncurses
>>
>> How much functionality does ncurses give you on a Windows console when
>> there is no ANSI driver loaded?
>
> I can't say, not having touched ncurses for years.  However, I can
> tell you that there is no need for any ANSI driver, as there is an
> entire Windows Console API available to handle such things.

Yes. I suppose I was asking, rather indirectly, does ncurses use it?

-- 
Ben.

[toc] | [prev] | [next] | [standalone]


#8464

FromNobody <nobody@nowhere.com>
Date2011-07-19 00:41 +0100
Message-ID<pan.2011.07.18.23.41.33.648000@nowhere.com>
In reply to#8428
On Mon, 18 Jul 2011 15:34:03 +0200, Heinrich Wolf wrote:

> clear() is defined on Unix in curses.h

If you just need to clear the screen, linking against curses is overkill.
system("clear") is the way to go here (and the usual warnings about
system() don't really apply here).

As for portability: my inclination would be to rely upon a macro
containing the command, and set it in a config.h file, or set it in the
Makefile and pass it via -D. That allows for passing an absolute path, or
an alternate command if a particular system doesn't have "clear" (or if
it's broken).

[toc] | [prev] | [next] | [standalone]


#8465

FromIan Collins <ian-news@hotmail.com>
Date2011-07-19 11:47 +1200
Message-ID<98jv20F8muU1@mid.individual.net>
In reply to#8464
On 07/19/11 11:41 AM, Nobody wrote:
> On Mon, 18 Jul 2011 15:34:03 +0200, Heinrich Wolf wrote:
>
>> clear() is defined on Unix in curses.h
>
> If you just need to clear the screen, linking against curses is overkill.
> system("clear") is the way to go here (and the usual warnings about
> system() don't really apply here).

Why is using a library function "overkill" compared to spawning a new 
process just to clear the screen?

-- 
Ian Collins

[toc] | [prev] | [next] | [standalone]


#8470

FromKeith Thompson <kst-u@mib.org>
Date2011-07-18 19:08 -0700
Message-ID<lnd3h7m399.fsf@nuthaus.mib.org>
In reply to#8465
Ian Collins <ian-news@hotmail.com> writes:
> On 07/19/11 11:41 AM, Nobody wrote:
>> On Mon, 18 Jul 2011 15:34:03 +0200, Heinrich Wolf wrote:
>>> clear() is defined on Unix in curses.h
>>
>> If you just need to clear the screen, linking against curses is overkill.
>> system("clear") is the way to go here (and the usual warnings about
>> system() don't really apply here).
>
> Why is using a library function "overkill" compared to spawning a new 
> process just to clear the screen?

Perhaps because curses tends to be used by programs that need
complete control over the screen, including keeping track of what
character appears at every position, whereas clearing the screen
is a much simpler operation.

The time it takes to spawn a process isn't likely to be significant.

-- 
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"

[toc] | [prev] | [next] | [standalone]


#8572

FromPhil Carmody <thefatphil_demunged@yahoo.co.uk>
Date2011-07-22 14:58 +0300
Message-ID<87sjpyttlu.fsf@bazspaz.fatphil.org>
In reply to#8470
Keith Thompson <kst-u@mib.org> writes:
> Ian Collins <ian-news@hotmail.com> writes:
> > On 07/19/11 11:41 AM, Nobody wrote:
> >> On Mon, 18 Jul 2011 15:34:03 +0200, Heinrich Wolf wrote:
> >>> clear() is defined on Unix in curses.h
> >>
> >> If you just need to clear the screen, linking against curses is overkill.
> >> system("clear") is the way to go here (and the usual warnings about
> >> system() don't really apply here).
> >
> > Why is using a library function "overkill" compared to spawning a new 
> > process just to clear the screen?
> 
> Perhaps because curses tends to be used by programs that need
> complete control over the screen, including keeping track of what
> character appears at every position, whereas clearing the screen
> is a much simpler operation.
> 
> The time it takes to spawn a process isn't likely to be significant.

What if the spawning of the process will cause cgroups to notify 
a user-space agent which will then potentially do re-jigging of
other processes properties? You're context switching all over the
place unnecessarily.

However, one technique I've seen in the past is to use system() to
call 'clear' or whatever, but rather than letting what it produces
just go to the controlling terminal, it's been read into the C program
and cached. Then to actually clear the screen, you just print out
the cached sequence. That at least reduces your system()s to 1.

Phil
-- 
"At least you know where you are with Microsoft."
"True. I just wish I'd brought a paddle." -- Matthew Vernon

[toc] | [prev] | [next] | [standalone]


#8591

FromKeith Thompson <kst-u@mib.org>
Date2011-07-22 09:42 -0700
Message-ID<lnei1ijmgi.fsf@nuthaus.mib.org>
In reply to#8572
Phil Carmody <thefatphil_demunged@yahoo.co.uk> writes:
> Keith Thompson <kst-u@mib.org> writes:
>> Ian Collins <ian-news@hotmail.com> writes:
>> > On 07/19/11 11:41 AM, Nobody wrote:
>> >> On Mon, 18 Jul 2011 15:34:03 +0200, Heinrich Wolf wrote:
>> >>> clear() is defined on Unix in curses.h
>> >>
>> >> If you just need to clear the screen, linking against curses is overkill.
>> >> system("clear") is the way to go here (and the usual warnings about
>> >> system() don't really apply here).
>> >
>> > Why is using a library function "overkill" compared to spawning a new 
>> > process just to clear the screen?
>> 
>> Perhaps because curses tends to be used by programs that need
>> complete control over the screen, including keeping track of what
>> character appears at every position, whereas clearing the screen
>> is a much simpler operation.
>> 
>> The time it takes to spawn a process isn't likely to be significant.
>
> What if the spawning of the process will cause cgroups to notify 
> a user-space agent which will then potentially do re-jigging of
> other processes properties? You're context switching all over the
> place unnecessarily.

Yes, and?  Does this cause measurable harm?

> However, one technique I've seen in the past is to use system() to
> call 'clear' or whatever, but rather than letting what it produces
> just go to the controlling terminal, it's been read into the C program
> and cached. Then to actually clear the screen, you just print out
> the cached sequence. That at least reduces your system()s to 1.

Yes, I think I've used that myself.

-- 
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"

[toc] | [prev] | [next] | [standalone]


#8600

FromPhil Carmody <thefatphil_demunged@yahoo.co.uk>
Date2011-07-22 22:32 +0300
Message-ID<8739hyt8l6.fsf@bazspaz.fatphil.org>
In reply to#8591
Keith Thompson <kst-u@mib.org> writes:
> Phil Carmody <thefatphil_demunged@yahoo.co.uk> writes:
> > Keith Thompson <kst-u@mib.org> writes:
> >> Ian Collins <ian-news@hotmail.com> writes:
> >> > On 07/19/11 11:41 AM, Nobody wrote:
> >> >> On Mon, 18 Jul 2011 15:34:03 +0200, Heinrich Wolf wrote:
> >> >>> clear() is defined on Unix in curses.h
> >> >>
> >> >> If you just need to clear the screen, linking against curses is overkill.
> >> >> system("clear") is the way to go here (and the usual warnings about
> >> >> system() don't really apply here).
> >> >
> >> > Why is using a library function "overkill" compared to spawning a new 
> >> > process just to clear the screen?
> >> 
> >> Perhaps because curses tends to be used by programs that need
> >> complete control over the screen, including keeping track of what
> >> character appears at every position, whereas clearing the screen
> >> is a much simpler operation.
> >> 
> >> The time it takes to spawn a process isn't likely to be significant.
> >
> > What if the spawning of the process will cause cgroups to notify 
> > a user-space agent which will then potentially do re-jigging of
> > other processes properties? You're context switching all over the
> > place unnecessarily.
> 
> Yes, and?  Does this cause measurable harm?

Yeah. Can you see our Maemo bugzilla - if so, look at the bugs 
assigned to me currently....

Phil
-- 
"At least you know where you are with Microsoft."
"True. I just wish I'd brought a paddle." -- Matthew Vernon

[toc] | [prev] | [next] | [standalone]


#8603

FromKeith Thompson <kst-u@mib.org>
Date2011-07-22 13:16 -0700
Message-ID<lnwrfahy0c.fsf@nuthaus.mib.org>
In reply to#8600
Phil Carmody <thefatphil_demunged@yahoo.co.uk> writes:
> Keith Thompson <kst-u@mib.org> writes:
>> Phil Carmody <thefatphil_demunged@yahoo.co.uk> writes:
>> > Keith Thompson <kst-u@mib.org> writes:
>> >> Ian Collins <ian-news@hotmail.com> writes:
>> >> > On 07/19/11 11:41 AM, Nobody wrote:
>> >> >> On Mon, 18 Jul 2011 15:34:03 +0200, Heinrich Wolf wrote:
>> >> >>> clear() is defined on Unix in curses.h
>> >> >>
>> >> >> If you just need to clear the screen, linking against curses is overkill.
>> >> >> system("clear") is the way to go here (and the usual warnings about
>> >> >> system() don't really apply here).
>> >> >
>> >> > Why is using a library function "overkill" compared to spawning a new 
>> >> > process just to clear the screen?
>> >> 
>> >> Perhaps because curses tends to be used by programs that need
>> >> complete control over the screen, including keeping track of what
>> >> character appears at every position, whereas clearing the screen
>> >> is a much simpler operation.
>> >> 
>> >> The time it takes to spawn a process isn't likely to be significant.
>> >
>> > What if the spawning of the process will cause cgroups to notify 
>> > a user-space agent which will then potentially do re-jigging of
>> > other processes properties? You're context switching all over the
>> > place unnecessarily.
>> 
>> Yes, and?  Does this cause measurable harm?
>
> Yeah. Can you see our Maemo bugzilla - if so, look at the bugs 
> assigned to me currently....

I don't think I can; I'll have to take your word for it.

-- 
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"

[toc] | [prev] | [next] | [standalone]


#8481

FromNobody <nobody@nowhere.com>
Date2011-07-19 12:56 +0100
Message-ID<pan.2011.07.19.11.56.37.163000@nowhere.com>
In reply to#8465
On Tue, 19 Jul 2011 11:47:07 +1200, Ian Collins wrote:

>> If you just need to clear the screen, linking against curses is overkill.
>> system("clear") is the way to go here (and the usual warnings about
>> system() don't really apply here).
> 
> Why is using a library function "overkill" compared to spawning a new 
> process just to clear the screen?

Because linking creates a hard dependency upon the library. If the library
(or one of its dependencies) doesn't exist, the program fails to run.

Also, curses is a fairly heavyweight library which exerts a lot of
control over the terminal, and which isn't straightforward to use (e.g.
you have to install signal handlers to ensure that the terminal state is
restored if the process is suspended or terminated abnormally).

If you only need to write escape/control sequences in a portable manner,
you're better off using termcap/terminfo to determine the appropriate
sequences. However, there are a lot of portability issues here. E.g.
the choice of the termcap or terminfo database may be coupled to the
choice of the termcap or terminfo API, or it may be orthogonal. Some
systems separate the terminfo API into a separate libtinfo, on others it's
only available via the curses library.

[toc] | [prev] | [next] | [standalone]


#8441

FromKenneth Brody <kenbrody@spamcop.net>
Date2011-07-18 14:06 -0400
Message-ID<76adncJb4euG67nTnZ2dnUVZ_jCdnZ2d@bestweb.net>
In reply to#8423
On 7/18/2011 7:34 AM, Ben Bacarisse wrote:
[...]
> 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.
[...]

That only works on a terminal, or within a terminal/console window, that 
understands ANSI control sequences.  This has not been the case on Windows 
for many years, and is not necessarily true on many terminal emulators.  The 
above program gives this output in a Windows console window:

←[H←[2J

I don't know how that will be shown after NNTP gets through it it, but it's:

     (left arrow)(left bracket)(capital H)(left arrow)(left bracket)
     (two)(capital J)

That's because sending ESC to stdout generates a little left-arrow character.

-- 
Kenneth Brody

[toc] | [prev] | [next] | [standalone]


#8443

FromKeith Thompson <kst-u@mib.org>
Date2011-07-18 11:11 -0700
Message-ID<lnwrffmpaq.fsf@nuthaus.mib.org>
In reply to#8423
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"

[toc] | [prev] | [next] | [standalone]


#8461

FromGeoff <geoff@invalid.invalid>
Date2011-07-18 18:06 -0500
Message-ID<clcm-20110718-0001@plethora.net>
In reply to#8404
On Sun, 17 Jul 2011 22:49:38 -0500 (CDT), happytoday
<ehabaziz2001@gmail.com> wrote:

>I comile C programs for bothe platforms : sunstudio using cc , visual
>studio 6 . Is there a command to differeniate which platform I compile
>for . That in order to use the the system command .
>
>For example :
>
>If (unixplatform)
>system("clear");
>else
>system("cls")

The Microsoft predefined macros _WIN32 and _MSC_VER come to mind,
recently _WIN64. 

http://msdn.microsoft.com/en-us/library/aa273918(v=VS.60).aspx

http://msdn.microsoft.com/en-us/library/b0084kay

I suppose you could set unixplatform true by default and set it false
depending on the return from a conditionally-compiled GetVersionEx
call.

http://support.microsoft.com/kb/307394
-- 
comp.lang.c.moderated - moderation address: clcm@plethora.net -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line.  Sorry.

[toc] | [prev] | [next] | [standalone]


#8462

From"Waldek M." <wm@localhost.localdomain>
Date2011-07-18 18:07 -0500
Message-ID<clcm-20110718-0002@plethora.net>
In reply to#8404
Dnia Sun, 17 Jul 2011 22:49:38 -0500 (CDT), happytoday napisał(a):
> I comile C programs for bothe platforms : sunstudio using cc , visual
> studio 6 . Is there a command to differeniate which platform I compile
> for . That in order to use the the system command .
> 
> For example :
> 
> If (unixplatform)
> system("clear");
> else
> system("cls")

Ugh. First of all, do not use system(). There are good
reasons for that, search google for them.

Secondly, you use preprocessor for the platform checking;
compilers present the appropriate symbols.

Third - don't cross-post, and if you have to, set FUT.

Br.
Waldek
-- 
comp.lang.c.moderated - moderation address: clcm@plethora.net -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line.  Sorry.

[toc] | [prev] | [next] | [standalone]


Page 1 of 2  [1] 2  Next page →

Back to top | Article view | comp.lang.c


csiph-web