Hi, I'm using your keil IDE for stm32 programming.To improve the readability and safty of my code, I always like to use enum type. Sometimes I need to transfer data from the mcu to my pc, and in some wireless app, the number of bytes that can be transfered is fixed. I want to use struct and enum for the transfered data, so I need to strictly defined the sizeof my user-defined enum type. That is, I want to specify the underlying type of the enum type. But this is not available in the iso 2003 standard. I've tested that the default underlying type has the smallest sizeof(enum_type_name) that can represent all the enumerator values defined in the enumeration. But you know, things Without Any Warranty is not good. So I wrote this e-mail to suggest that mdk C++ compiler should support the new c++ standard.
last, for the explicitness of what I mean: I need the define an enum type like this, enum Direction: char{ /* underlying type is char, so sizeof(Direction) is 1 */ LEFT, RIGHT }; this code is valid when i wrote it in visual studio, but it cannot be compiled use mdk.
you can refer to “7.2 Enumeration declarations” of the doc ISO/IEC 14882 - Information technology — Programming languages — C++
sincerely, Pony279 from china.
Google, "Serialisation" (or "Serialization").
eg, see: en.wikipedia.org/.../Serialization
www.keil.com/.../search.asp
to Andrew Neil,
Thanks. It is a good way to solve the problem of padding in struct.
----------------------------------------------------------------------
from en.wikipedia.org/.../Serialization:
"In computer science, in the context of data storage and transmission, serialization is the process of converting a data structure or object state into a format that can be stored (for example, in a file or memory buffer, or transmitted across a network connection link) and "resurrected" later in the same or another computer environment."
"C and C++ do not provide direct support for serialization. It is however possible to write your own serialization functions, since both languages support writing binary data."