Code
I've got a function which I can write in one of four possible ways:
int do_or_die(int retval);
int do_or_die(ssize_t retval);
ssize_t do_or_die(int retval);
ssize_t do_or_die(ssize_t retval);
And then it will be called with both of these ways for library functions:
written = do_or_die(write(...)); // POSIX write returns ssize_t
printed = do_or_die(printf(...)); // printf returns int
Questions
- Which prototype should I use?
- What types should I give to
written
and printed
?
I want to have the most robust and standard code, while still having just one do_or_die
function.
I am using C99 in this case, but if answer is different for C11, then I'd like to know that too, for future.
question from:
https://stackoverflow.com/questions/19224655/using-ssize-t-vs-int 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…