Bill Cunningham said:
Yes. Would return -1 from a function other than main be ok?
Yes of course. You can return any int from a function declared as
returning an int.
There's no problem returning -1 from main() either, as far as the C
program is concerned. All that's undefined is how the "host
environment" - the shell or operating system or parent program -
interprets it. 0 (or EXIT_SUCCESS) indicates success. EXIT_FAILURE
indicates failure. What anything else means depends on your system.
Most of my programs return 0, 1, or sometimes a larger value, which
can be interpreted reasonably in the unix environments I intend them
for. But you can perfectly well run them in other environments; you
just have to ensure that you run them in such a way that the return
value is not misinterpreted. I suppose it's possible that somewhere
there's an operating system that always shuts down completely if any
C program calls exit(1), but the solution to that is to get a different
operating system.
-- Richard