Why do I need to create a single record in the structure?

It is written by someone who left the company. I see no reason for this, and I am curious if something is missing for me there.

enum thing_type_e { OPTION_A = 0, OPTION_B, OPTION_C, OPTION_D }; struct thing_type_data_s { enum_type_e mVariable; }; 

I suggested that it might add more to the structure, but looking at how it is used, I don’t think so.

The ban "he was going to add more to the structure", why you need to pack the only listing in the structure? Is there any motivation that I don't think about?

Update:

As stated in the comments, he used it this way:

 void process_thing_type(thing_type_data_s* ParamVariable) { local_variable = ParamVariable->mVariable; ... } 

It was originally built using GCC 3.3.5, if that matters.

+7
c ++ c enums struct
source share
2 answers

Perhaps for some type of security. Old-style modes are implicitly converted to integral types, and this is not always desirable. In addition, they are not protected.

In C ++ 11, narrow command enumerations (or "class enumerations") are added to eliminate both of these problems.

Here is an example:

 void foo(int) {} int main() { foo(OPTION_A); // OK thing_type_data_s s = { OPTION_A }; foo(s); // Error } 
+13
source share

Are there other structures with the same element type at first, but differently? It can use struct thing_type_data_s in baseclass-y style. But who knows, you marked the question as C and C ++. I would make sense in C, at least.

0
source share

All Articles