I know that the title is not self explicative, but I couldn't express in a few words. Anyway, the problem is that I have a C function that returns a struct consisting of 3 integers. Here it is its definition.
typedef struct {
uint8_t r;
uint8_t g;
uint8_t b;
} Color;
and here it is the function
Color PPMImage_getPixel(PPMImage *ppmImage, uint32_t x, uint32_t y) {
// FIXME: Check if (x, y) is in bounds.
return ppmImage->data[y * ppmImage->width + x];
}
Now when a specific condition fails I want to return an error value that tells the caller that the function encountered an error, but I can't since the return value is a struct with 3 unsigned integers and I can't, for example, set each field to -1 or return NULL because I'm not returning a pointer. Is there an elegant and efficient way to do that?