What should I do to get the whole return value of c-program from command line?

bash, c, return, unix

Solution

Exit codes on Unix are restricted to a single byte. If you want to output more, you could write it to stdout or to a file instead.

Then why does the C standard decree that `main` returns `int` and not `char`? I have no idea...

Problem

I have a simple C-program `"./my_program"` ``` #include <stdio.h> int main (int argc , char **argv) { unsigned int return_result = 0x474; printf("return_result = %d = 0x%x \n",return_result,return_result); return return_result; } ``` As a result, this program prints: ``` return_result = 1140 = 0x474 ``` I want to get a return value of c-program within bash script. According to this link Anyway to get return value of c program from command line? I should get this variable from $? But when I launch such commands consequence: ``` ./my_program echo $? ``` I get ``` 116 ``` It is obviously, that 116 = 0x74 (the lowest byte). But I'd like to get the whole unsigned int value. What is wrong? What should I do to get the whole return value of c-program from command line? This is not about only "unsigned int" type. What should I do in case if I created some complicated type, for example, - structure. I tried this: ``` return ((unsigned int) return_result_section_size); ``` It doesn't work.

Original source

Related problems