delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/07/26/16:17:57

From: "John M. Aldrich" <fighteer AT cs DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: optimising
Date: Tue, 22 Jul 1997 15:54:26 +0000
Organization: Two pounds of chaos and a pinch of salt
Lines: 65
Message-ID: <33D4D775.318A@cs.com>
References: <01bc9660$b58d62a0$c4fa41ce AT drkwatr>
Reply-To: fighteer AT cs DOT com
NNTP-Posting-Host: ppp108.cs.com
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

DrkWatr wrote:
> 
> I was wondering if there is a program that will
> optimisize your c source, and still let you view it as c source? Thus
> allowing me to learn better programming habits. Also i cannot find any real
> good info on how to spawn another application(with command-line args) from
> within another. Can anybody be of service?

Most optimization is done at the assembly level by the compiler.  It
would be very difficult to write a tool to do this directly to the
source code.  Besides, what the compiler thinks of as optimization is
unlikely to be what you mean here; it places frequently used variables
in registers, rearranges instructions to fit the timing requirements of
the CPU's pipeline, breaks down loops whenever possible, eliminates
common subexpressions, inlines functions, and a zillion other things. 
To take a brief look at the major optimization flags, examine the gcc
docs under "info gcc invoking optimize".

There is a GNU program named "indent" that pretties up your source code,
making the spacing and indentation consistent.  I haven't used it but
there ought to be a copy on SimTel.

As for spawning other applications, you may use any of the following
functions:

system()
popen()/pclose()
spawn*()
exec*()
fork()
pipe()

Each has a purpose, depending on what you want to do.

system() simply invokes the command line you pass it as a parameter:

    system( "c:/djgpp/gcc -o myprog.exe myprog.c" );

popen() works like system(), but redirects a program's standard input or
standard output to a file, which you can then write to or read from in
your program.  pclose() terminates the child process.  Example:

    FILE *pipe;
    pipe = popen( "more", "w" );
    fprintf( pipe, "Four score and seven years ...\n" );
    pclose( pipe );


The spawn*() family of functions allows you to invoke other programs by
explicitly specifying the arguments and environment.  The exec*() family
is similar to spawn*(), but does not return control to your program.

fork() and pipe() are functions designed specifically for multitasking
operating systems.  In the current DJGPP library, they do nothing.

Look these up in the libc docs ("info libc alpha system", "info libc
alpha popen", "info libc func process") for further information.

-- 
---------------------------------------------------------------------
| John M. Aldrich, aka Fighteer I  |     mailto:fighteer AT cs DOT com     |
|    *  Proud user of DJGPP!  *    |   http://www.cs.com/fighteer   |
|    ObJoke:  If Bill Gates were a robber, not only would he        |
|     shoot you, but he'd send you a bill for the bullets.          |
---------------------------------------------------------------------

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019