f



When will exit(0) fail to exit?

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.


0
junw2000 (224)
1/21/2008 12:19:27 AM
comp.lang.c++ 49423 articles. 7 followers. Post Follow

5 Replies
541 Views

Similar Articles

[PageSpeed] 0

junw2000@gmail.com wrote:
> 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() :

#include <cstdlib>


> 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.
0
ivranos1 (46)
1/21/2008 12:27:56 AM
junw2000@gmail.com wrote:
> 
> 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?

-- 
Ian Collins.
0
ian-news (10155)
1/21/2008 3:23:37 AM
On Jan 20, 7:23=A0pm, Ian Collins <ian-n...@hotmail.com> wrote:
> junw2...@gmail.com wrote:
>
> > 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?
>
> --
> Ian Collins.

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.
0
junw2000 (224)
1/21/2008 5:59:56 AM
junw2000@gmail.com wrote:
> On Jan 20, 7:23 pm, Ian Collins <ian-n...@hotmail.com> wrote:
>> junw2...@gmail.com wrote:
>>
>>> 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?
>>
*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.

-- 
Ian Collins.
0
ian-news (10155)
1/21/2008 6:39:00 AM
<junw2000@gmail.com> wrote in message 
news:37b5b395-d673-4ade-8733-9627a3a7e758@i12g2000prf.googlegroups.com...

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

--

Pascal


0
nospam48 (2784)
1/21/2008 7:08:04 AM
Reply: