Originally Posted by
kermit
Well on a UNIX based system you can return any int number you like, but you are not guaranteed that number will return properly. If we use your example, you will get a return of 255, not -1.
So, what do you get when your main() returns EXIT_FAILURE (defined as 1). On my linux box I get 256, not 1. I don't see anything more portable about EXIT_FAILURE than any other value.
Dave
Test Code:
Code:
/* z.c */
/* Compile this with gcc -o z z.c */
#include <stdio.h>
int main()
{
int innum;
int retval;
char inbuf[BUFSIZ];
printf("Enter an integer value to return to main: ");
fgets(inbuf, BUFSIZ, stdin);
if (sscanf(inbuf, "%d", &innum) == 1) {
retval = innum;
}
else{
printf("I was looking for an integer\n");
retval = -99;
}
printf("I am returning with retval = %d\n", retval);
return retval;
}
Code:
/* y.c */
/* compile this with gcc -o y y.c */
#include <stdio.h>
#include <stdlib.h>
int main()
{
int x;
x = system("./z");
printf ("x = %d, (0x%08x hex)\n", x,x);
return 0;
}
now enter
./y
and see what return values you get.
Try it with execl, spawn, etc. Also try exit() instead of return().
Regards,
Dave