Return value range of the main function

Nyan picture Nyan · Mar 1, 2011 · Viewed 8.8k times · Source

What does standard say about main return values range? Say only up to 255?

Because

int main(void){
return 256;
}
echo $? ;  # out 0

Answer

Jerry Coffin picture Jerry Coffin · Mar 1, 2011

The standard doesn't say. 0, EXIT_SUCCESS and EXIT_FAILURE have (sort of) specified meanings. Anything else depends on the implementation.

At the present time, most Unix-based systems only support 8-bit return values. Windows supports (at least) a 32-bit return value. I haven't checked whether 64-bit Windows supports a 64-bit return value, but I rather doubt it, since even 64-bit Windows normally still uses a 32-bit int.