ВходНаше всё Теги codebook 无线电组件 Поиск Опросы Закон Суббота
11 мая
95983 Топик полностью
htsoft (30.07.2007 21:46, просмотров: 1) ответил =AlexD= на Что мне делать я сам знаю. Речь шла о другом.
я говорил о том, что надо использовать const, а приведённый пример как раз показывает что и enum плохая замена define, разве не об этом речь? http://www.chris-lott.org/resources/cstyle/CppCodingStandard.html#gconstants
To Use Enums or Not to Use Enums C++ allows constant variables, which should deprecate the use of enums as constants. Unfortunately, in most compilers constants take space. Some compilers will remove constants, but not all. Constants taking space precludes them from being used in tight memory environments like embedded systems. Workstation users should use constants and ignore the rest of this discussion. In general enums are preferred to #define as enums are understood by the debugger. Be aware enums are not of a guaranteed size. So if you have a type that can take a known range of values and it is transported in a message you can't use an enum as the type. Use the correct integer size and use constants or #define. Casting between integers and enums is very error prone as you could cast a value not in the enum.