J
John Galt
I am writing a rudimentary shell. The (idealized) code is like this:
/* read_cmd returns argv */
char **read_cmd();
shell()
{
char **cmd;
while {
cmd = read_cmd();
if (cmd == (char **)0) /* user just hit '\n' */
continue;
else if (cmd == (char **)-1) /* EOF */
break;
else {
... processing
}
}
}
My questions are:
1. Is it OK to return (char **)1 and (char **)-1 in a function?
OK as in, is it legal, is it acceptable, is it portable. Are there
better ways to do this?
2. Can a pointer have a value of -1 in C? What is the official or
definitive word(s) on this?
I have found that it works OK on Solaris, Linux & zSeries.
TIA for any advice,
John Galt.
/* read_cmd returns argv */
char **read_cmd();
shell()
{
char **cmd;
while {
cmd = read_cmd();
if (cmd == (char **)0) /* user just hit '\n' */
continue;
else if (cmd == (char **)-1) /* EOF */
break;
else {
... processing
}
}
}
My questions are:
1. Is it OK to return (char **)1 and (char **)-1 in a function?
OK as in, is it legal, is it acceptable, is it portable. Are there
better ways to do this?
2. Can a pointer have a value of -1 in C? What is the official or
definitive word(s) on this?
I have found that it works OK on Solaris, Linux & zSeries.
TIA for any advice,
John Galt.