return from main

P

Pietro Cerutti

Hi group,
please tell me if this rather belongs to comp.unix.programmer or such..

I would like to know whether there is a portable way to return a integer
type not limited to 0xff from main.
In the man page of exit it's stated that the value passed to it is &'d
with 0xff before being returned to the parent.

The goal here it to return a unsigned long to the caller (e.g. shell).

Thanks,
 
M

Mark Bluemel

Pietro said:
Hi group,
please tell me if this rather belongs to comp.unix.programmer or such..

OK - this belongs in comp.unix.programmer
I would like to know whether there is a portable way to return a integer
type not limited to 0xff from main.
In the man page of exit it's stated that the value passed to it is &'d
with 0xff before being returned to the parent.

The goal here it to return a unsigned long to the caller (e.g. shell).

The standard simply says that dependent on the argument passed to exit()
an implementation-specific indication of success or failure is returned.

In the case of Unix, that implementation specific indication is
restricted to 8-bits...
 
P

Philip Potter

Pietro said:
Hi group,
please tell me if this rather belongs to comp.unix.programmer or such..

I would like to know whether there is a portable way to return a integer
type not limited to 0xff from main.

If you really are concerned about portability, the only fully portable
values one can return from main, or use as an argument to exit(), are
EXIT_SUCCESS, EXIT_FAILURE, and 0, which is equivalent to EXIT_SUCCESS.

There are other ways of communicating with the calling process. You
could write your integer to stdout using printf and have the caller read
it back in, for example.

Phil
 
S

santosh

Philip said:
If you really are concerned about portability, the only fully portable
values one can return from main, or use as an argument to exit(), are
EXIT_SUCCESS, EXIT_FAILURE, and 0, which is equivalent to
EXIT_SUCCESS.

There are other ways of communicating with the calling process. You
could write your integer to stdout using printf and have the caller
read it back in, for example.

This is feasible only if the program uses stdout for no other purpose. A
better method might be to create a file with the return value as it's
content.

This is a case where to get more flexibility you'll probably have to
investigate system specific mechanisms.
 

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
474,431
Messages
2,571,679
Members
48,796
Latest member
Greg L.

Latest Threads

Top