[GRASS-dev] lib fn to convert int color number to RGB values?

Ivan Shmakov ivan at theory.asu.ru
Wed Jan 30 08:37:52 EST 2008


>>>>> Moritz Lennert <mlennert at club.worldonline.be> writes:

[...]

 >>> int D_color_number_to_RGB(int color, int &r, int &g, int &b)

[...]

 >>> 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])

[...]

     The normal return value from `open' is a non-negative integer file
     descriptor.  In the case of an error, a value of -1 is returned
     instead.  [...]
--cut: (libc) Opening and Closing Files--

	Note that there's useful, and always non-negative, value to be
	returned on success.  Negative values are therefore reserved for
	errors (from the point of view of the application programmer;
	the only value which may actually be returned by the function in
	the case of error is `-1'.)

--cut: (libc) Process Group Functions--
 -- Function: int setpgid (pid_t PID, pid_t PGID)

[...]

     If the operation is successful, `setpgid' returns zero.  Otherwise
     it returns `-1'.  [...]
--cut: (libc) Process Group Functions--

	And there is no such a value, so zero is used to indicate
	success.  Negative values are again reserved for errors.



More information about the grass-dev mailing list