When will exit(0) fail to exit?

J

junw2000

My program is about several thousands lines. It takes arguements from
the command line.
If no arguement is given, it should simply exist. Below is the
architectureof main() :

int main(int argc, char *argv[])
{
if( argc == 1 )
{
cout << "NO ARGUEMENT"<<endl;
exit(0);
}


//Other parts of the code

return 0; //LastLine

}


It also links with other libraries.
If no arguement is given on command line, it only outputs "NO
ARGUEMENT", then hangs there.
The exit(0) can not exit. Why exit(0) fails to exit from main()?

If I give correct arguements at command line, the program also hangs.
The return 0 at the LastLine can not exit, either.

The code links some C++ libraries. It only hangs on AIX systems. But
for Linux, it works fine. Why?

I find that maybe a C++ library causes the problem. What should I do?
I have to link that library. Otherwise, the linker complains
"Undefined symbols", although some symbols are not needed in my code,
but they are used in other libraries.


Thanks.
 
I

Ioannis Vranos

My program is about several thousands lines. It takes arguements from
the command line.
If no arguement is given, it should simply exist. Below is the
architectureof main() :

int main(int argc, char *argv[])
{ using namespace std;
>
if( argc == 1 )
{
cout << "NO ARGUEMENT"<<endl;
exit(0);
}


//Other parts of the code

return 0; //LastLine

}


It also links with other libraries.
If no arguement is given on command line, it only outputs "NO
ARGUEMENT", then hangs there.
The exit(0) can not exit. Why exit(0) fails to exit from main()?

If I give correct arguements at command line, the program also hangs.
The return 0 at the LastLine can not exit, either.

The code links some C++ libraries. It only hangs on AIX systems. But
for Linux, it works fine. Why?

I find that maybe a C++ library causes the problem. What should I do?
I have to link that library. Otherwise, the linker complains
"Undefined symbols", although some symbols are not needed in my code,
but they are used in other libraries.


Supposing you included <cstdlib> as I did above, it sounds like a bug of
your compiler. However you do not need to call exit(). A simple "return
0;" statement would suffice.
 
I

Ian Collins

The code links some C++ libraries. It only hangs on AIX systems. But
for Linux, it works fine. Why?
Did you follow any of the advice given when you asked this on c.l.c?
 
J

junw2000

Did you follow any of the advice given when you asked this on c.l.c?

I find that one of the library that I link causes the problem. It
defines a static object. My code does not use that static object. When
exit the main(), the destructor is called and hangs.
But why it works on some systems?

Thanks.
 
I

Ian Collins

*Please don't quote signatures*
I find that one of the library that I link causes the problem. It
defines a static object. My code does not use that static object. When
exit the main(), the destructor is called and hangs.
But why it works on some systems?
Hangs doing what?

It sounds like you have a platform issue rather than a language one.
The point where the hang occurs should provide your answer.
 
P

Pascal

I find that maybe a C++ library causes the problem. What should I do?

When it "hangs", just attach it to a debugger and break. I think that you
can see where and why it "hangs"...
 

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

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top