Mapping Index to a String in C
Your code is completely safe and free of undefined behavior.

You have used const wherever it is useful and good style.

That's great. :)

One little source of confusion, though. The list of device names contains 9 entries, but the code compares something with an 8. This 8 is confusing since the last valid index in an array is just an implementation detail. (In other programming languages like Lua or Pascal, it could be different.) Contrary, the number of devices is more interesting to any reader. Therefore, readers expect to read that number. Whatever number you write in the code, make sure it's an interesting number.

Therefore, it's better to use the idiomatic code below:

size_t size = sizeof device_names / sizeof device_names[0];
if (device_index &lt; size) {
    return device_names[device_index];
}
return "";


This code doesn't give any clue about the actual number of devices, which makes the code more robust when a device name is added to the list.