Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Program exit status and $?

Tags:

c++

exit-code

C++ Primer book i read says that

The value returned from main is accessed in a system dependent manner. On both UNIX and Windows systems, afar executing the program you must issue an appropriate echo command. On UNIX we obtain the status by echo $?

So, if the program is

int main ()
{
    return -88;
}

Why does echo $? not return it? (168 is printed upon echo)

like image 827
James Raitsev Avatar asked Sep 11 '26 22:09

James Raitsev


1 Answers

It does, sort of. It'll convert the value to an unsigned 8-bit value, though, which is 256 − 88 = 168. That's part of the system-dependent mannerism.

like image 64
Kerrek SB Avatar answered Sep 14 '26 13:09

Kerrek SB



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!