[CLUE-Tech] C programming question
Keith Hellman
kehellman at yahoo.com
Wed Dec 12 11:45:53 MST 2001
I would do something like this - many variations exist however, for instance keeping beep() as a
static inline within myincludes.h - then you don't have an extra .c module.
CAVEATS: Most of this is from memory, but I think it works. I am assuming that gcc sets DEBUG if
-g option is provided; if thats not the case you would use 'gcc -DDEBUG -g ...'
HTH
myincludes.h =================================================================
#ifdef DEBUG
void beep( void );
#else
static inline void beep( void ) {}
#endif
mylib.c ======================================================================
#ifdef DEBUG
void beep( void )
{
int c;
char* beep_args[2] = { "/myhome/bin/beep", NULL };
switch( c = fork()) {
case 0 : /* child */
execv( beep_args[0], beep_args );
_exit(0)
break;
case -1 : /* yikes! */
break;
default : /* need to wait for execution to complete? */
{
int ec, again;
do {
again = 0;
ec = wait(c);
if(( ec == -1 ) && ( errno == EINTR )) again = 1;
} while( again );
return ec;
}
break;
}
return -1;
}
#endif
yourapp.c =======================================================================
#include <myincludes.h>
int main( int argc, char* argv[] )
{
/* Debug test */
beep();
return 0;
}
COMPILE LINES ===================================================================
# This line won't make noise
gcc -o yourapp yourapp.c mylib.c; ./yourapp
# This line will
gcc -g noisy yourapp.c mylib.c; ./noisy
--- Dave Price <davep at kinaole.org> wrote:
> I am trying to learn a bit more about C, and have a silly question for
> which i cannot find an answer.
>
> My PC does not have a speaker, so \a (terminal bell or alert) does
> nothing. I have written a simple stand alone program that beeps the
> soundcard with a short .wav file instead.
>
> Question: What is the 'right' way to setup this program so that i can
> have a single function beep() which i can import into other programs
> when desired?
>
> aloha (& TIA),
> dave
> _______________________________________________
> CLUE-Tech mailing list
> CLUE-Tech at clue.denver.co.us
> http://clue.denver.co.us/mailman/listinfo/clue-tech
=====
Keith E. Hellman
kehellman at yahoo.com
__________________________________________________
Do You Yahoo!?
Check out Yahoo! Shopping and Yahoo! Auctions for all of
your unique holiday gifts! Buy at http://shopping.yahoo.com
or bid at http://auctions.yahoo.com
More information about the clue-tech
mailing list