return int from main

G

Grant Schoep

Ok, back to basics here.

I was completly shocked and dismayed today when one of my apps returned an
error from main. Not so much that it returned an error, that was expected.
But what happened.

I swear that main was supposed to return "int", i.e. some postive/neg
integer of unknown byte lenght(compiler/platform depenendent byte lenght of
course)

So anyways.

I just found out, that on my current system. RedHat ES 3, the return status
from the shell is only an 8 byte unsigned integer. I swear I had more range
before, but that was under different shells and OS's.


So. Is this a OS, shell, or compiler limit?

Meaning, I want to code the correct thing, I just don't know now how to
validly code it, as I had thought main in C/C++ was always supposed to
return (int)

I'm switching my return codes to postive 0-255 value now. Not so bad as the
couple peices of software that interact with this I also now maintain. But
just would like more on this story.

-grant
 
A

Alf P. Steinbach

* Grant Schoep:
Ok, back to basics here.

I was completly shocked and dismayed today when one of my apps returned an
error from main. Not so much that it returned an error, that was expected.
But what happened.

I swear that main was supposed to return "int", i.e. some postive/neg
integer of unknown byte lenght(compiler/platform depenendent byte lenght of
course)

So anyways.

I just found out, that on my current system. RedHat ES 3, the return status
from the shell is only an 8 byte unsigned integer.

You mean 8 bits.

I swear I had more range
before, but that was under different shells and OS's.

So. Is this a OS, shell, or compiler limit?
Yes.


Meaning, I want to code the correct thing, I just don't know now how to
validly code it, as I had thought main in C/C++ was always supposed to
return (int)

The language defines only three values: 0, EXIT_SUCCESS, and EXIT_FAILURE,
where 0 and EXIT_SUCCESS have the same conceptual meaning, namely success,
and EXIT_SUCCESS is most probably but not necessarily defined as 0.
 
R

Rolf Magnus

Grant said:
Ok, back to basics here.

I was completly shocked and dismayed today when one of my apps returned an
error from main. Not so much that it returned an error, that was expected.
But what happened.

I swear that main was supposed to return "int", i.e. some postive/neg
integer of unknown byte lenght(compiler/platform depenendent byte lenght
of course)

So anyways.

I just found out, that on my current system. RedHat ES 3, the return
status from the shell is only an 8 byte unsigned integer. I swear I had
more range before, but that was under different shells and OS's.


So. Is this a OS, shell, or compiler limit?
Maybe.

Meaning, I want to code the correct thing, I just don't know now how to
validly code it, as I had thought main in C/C++ was always supposed to
return (int)

In Standard C++, the three values EXIT_FAILURE, EXIST_SUCCESS (from
<cstdlib>) and 0 are the only valid values that main can return. Most
platforms support more values - which is useful to indicate the type of
error - but the details are of course platform specific.
 
G

Grant Schoep

In Standard C++, the three values EXIT_FAILURE, EXIST_SUCCESS (from
<cstdlib>) and 0 are the only valid values that main can return. Most
platforms support more values - which is useful to indicate the type
of error - but the details are of course platform specific.

Cool. Like knowing more about Standard C++, really need to do more reading
on that. Since my only "customers" of this app are my other apps. I'll
happily stick with having more return codes. Though, I may change some as I
always endevor to make my code as standard and cross platform as possible.

Cheers
-grant
 

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,202
Messages
2,571,057
Members
47,665
Latest member
salkete

Latest Threads

Top