
Hi,
On 28-12-14 10:40, Ian Campbell wrote:
On Wed, 2014-12-24 at 20:06 +0100, Hans de Goede wrote:
+enum sunxi_monitor {
- sunxi_monitor_none,
- sunxi_monitor_dvi,
- sunxi_monitor_hdmi,
- sunxi_monitor_lcd,
- sunxi_monitor_vga,
+};
[...]
- const char *mon_desc[] = { "none", "dvi", "hdmi", "lcd", "vga" };
These risk getting out of sync. I half expect the array will be punted by the compiler into static storage anyway, so you could just make it a global up near the enum (and perhaps use the [sunxi_monitor_none] = "none" initialiser style).
Another option (which I think I prefer) would be a get_mon_desc helper with a switch in it over the enum, returning the const char *. Then the compiler will (hopefully) complain if a new enum is added without a corresponding description.
Yeah the compiler will complain then. I've gone with your suggestion to add a get_mon_desc helper, note that I did need to also add a SUNXI_MONITOR_LAST define to use in the loop to compare the user provided string with the get_mon_desc strings. I've put this directly under the enum to make it hard to overlook and skip it when updating the enum.
Regards,
Hans