Main loop

G

gamehack

Hi all,

I was wondering what's the way to create your own main loop? Say I want
to index file and the indexing should be happening in the main loop and
when there are no files to index, the process will just run as a
daemon. I know this is possible with a simple while(1) but what a about
a true main loop?

Regards
 
V

Vladimir S. Oka

gamehack said:
Hi all,

I was wondering what's the way to create your own main loop? Say I
want to index file and the indexing should be happening in the main
loop and when there are no files to index, the process will just run
as a daemon. I know this is possible with a simple while(1) but what a
about a true main loop?

Regards

I don't really understand what you mean by the "true main loop",
especially if it's not:

int main(void)
{
while (1)
{
/* do whatever */;
}
}

This is a perfectly acceptable and understandable way of running stuff
"forever" in a C program. Could you clarify, please?

Cheers

Vladimir

PS
There are also perfectly non-standard and non-portable ways of having
some function other than main() running as your "C" application, but I
don't think that's what you meant.
 
K

Kenneth Brody

gamehack said:
Hi all,

I was wondering what's the way to create your own main loop? Say I want
to index file and the indexing should be happening in the main loop and
when there are no files to index, the process will just run as a
daemon. I know this is possible with a simple while(1) but what a about
a true main loop?

What's not "true main" about:

int main(int argc,char *argv[])
{
while (1)
{
... everything here ...
}
return(0);
}

If you don't like that for some reason:

int main(int argc,char *argv[])
{
while (1)
{
main2(argc,argv);
}
return(0);
}

int main2(int argc,char *argv[])
{
... put everything that was "main()" here ...
}

What, exactly, are you trying to do?

--
+-------------------------+--------------------+-----------------------------+
| Kenneth J. Brody | www.hvcomputer.com | |
| kenbrody/at\spamcop.net | www.fptech.com | #include <std_disclaimer.h> |
+-------------------------+--------------------+-----------------------------+
Don't e-mail me at: <mailto:[email protected]>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,173
Messages
2,570,939
Members
47,484
Latest member
JackRichard

Latest Threads

Top