When talking about starting a new process, you can do it using int system(char* command)
. If you pass an non NULL parameter, you can get:
-1
if the child process cannot be started;note: in Unix/Linux the return code is located on the higher eight bits of the result, while the lower eight bits contain the termination reason code>{1}<, so a retcode equal to 1 will be returned as 256; you can get the actual return code by shifting the value eight bits to the right; there is also a macro named WEXITSTATUS() that does it for you.
Searching for the implementation of WEXITSTATUS()
it's a shift 8 bits to the right.
#define WEXITSTATUS(x) (_W_INT(x) >> 8)
This is the reason why I tend to think that return codes are 2 bytes (and also from >{1}<). The quote is from a C course found online.
P.s I would like to know the difference between the return code and termination reason code, aren't they the same?
Suppose a sensor uses a 16-bit integer or you want to create an integer that is always 16-bit. That is when the "int16_t" is used. It is always 16 bits on all Arduino boards.
As an example return code 0 is success and return code 3010 is reboot required, but there are many other codes that can help troubleshoot patch install issues. This isn't a comprehensive list. Our suggestion is to use your favorite search tool if the code isn't listed here. For instance, the return code 2147483647 isn't listed here.
Use a non-zero number to indicate an error. In your application, you can define your own error codes in an enumeration, and return the appropriate error code based on the scenario. For example, return a value of 1 to indicate that the required file is not present and a value of 2 to indicate that the file is in the wrong format.
That is mapping 65,536 uint16_tinto 65,535 int16_t. Something is missing. – chux - Reinstate Monica Jun 1 '17 at 19:50
There s different reasons for termination:
return
(explicitly or not)For each of theses terminations a code is accessible, respectively:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With