[GRASS-dev] lib fn to convert int color number to RGB values?
Glynn Clements
glynn at gclements.plus.com
Thu Jan 31 05:17:30 EST 2008
Ivan Shmakov wrote:
> >>> if (color <= 0) return 0;
>
> >> BTW, is it a GRASS convention to use 0 to indicate failure?
> >> Standard C library functions tend to use -1 for failure, while using
> >> non-negative values to indicate success.
>
> > The SUBMITTING file in the source code says:
>
> > 8. Exit status is defined as EXIT_SUCCESS or EXIT_FAILURE, e.g.
>
> > {
> > ...
> > if (G_parser (argc, argv))
> > exit (EXIT_FAILURE);
>
> > ...
> > exit (EXIT_SUCCESS);
> > }
>
> > AFAIU, these are defined in stlib as being respectively 0 and 1.
>
> Yes. But the conventions for the exit code of a program are
> hardly applicable to the return value of a function.
>
> Consider, e. g. (from ``The GNU C Library Reference Manual''):
>
> --cut: (libc) Opening and Closing Files--
> -- Function: int open (const char *FILENAME, int FLAGS[, mode_t MODE])
> --cut: (libc) Process Group Functions--
> -- Function: int setpgid (pid_t PID, pid_t PGID)
Those functions return a meaningful non-negative integer upon success.
GRASS functions which behave likewise normally return -1 for failure,
but functions which only return success or failure use C logic values,
with zero (false) for failure and non-zero (true) for success.
--
Glynn Clements <glynn at gclements.plus.com>
More information about the grass-dev
mailing list