Как насчет:
icon: [ icon0, icon1, icon2 ][area],
On further research, I discovered that this is behavior specific to the WindRiver Diab compiler. Please see the EDIT in the question for details.
Мне это кажется простым применением оператора запятой , который вычисляет свой первый аргумент, отбрасывает результат, а затем оценивает его второй аргумент.
В В данном случае он определяет, имеет ли литерал 2
размер 4. Часть « var
» не имеет значения.
Похоже на отвлекающий маневр. Я предполагаю, что вы случайно используете оператор запятой, а sizeof применяется к последнему значению.
As mentioned, the comma operator is being applied and sizeof is returning the size of an integer literal. Offhand this looks like an error on the author's part, but there could be some sinister coding happening.
sizeof expressions are not evaluated so they can be used for a number of tricky things. One example is to provide a reference for an otherwise unreferenced variable without causing the compiler to generate any code. See this article on creating a better assert macro for an example. Alexandrescu has some other examples of sizeof trickery in Modern C++ Design, if memory serves. It's possible, but not likely, that one of these non-obvious usages is intended.
Whatever the usage, if it's not commented in this situation then it's clearly not worth the trade-off in readability and should be changed.