
Stewart, Robert wrote:
Joshua Juran wrote:
On Aug 29, 2011, at 3:09 PM, Phil Endecott wrote:
Gordon Woodhull wrote:
If I had to write a conversion function, I would rather write it as an overload of a general-purpose converter, rather than giving it some ugly typeA2TypeB name.
Why is e.g. rgb_to_cmyk() "ugly"?
cmyk_t cmyk = rgb_to_cmyk( rgb );
That's why. Compare:
cmyk_t cmyk = cmyk_from_rgb( rgb );
I prefer this:
cmyk_t cmyk = to_cmyk(rgb);
That permits reusing "to_cmyk" for various types via overloading.
The problem with that is the (common?) case where rgb_t is a typedef for e.g. uint8_t[3]. This applies to other conversions too, e.g. time_t is a typedef for int, centigrade_t and farrenheit_t are both typedefs for float, etc. etc. Regards, Phil.