Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 908 Vote(s) - 3.55 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Why package a single enum in a struct?

#1
This is written by someone who has left the company. I can't see any reason to do this and am curious if there's something I am missing.

enum thing_type_e
{
OPTION_A = 0,
OPTION_B,
OPTION_C,
OPTION_D
};

struct thing_type_data_s
{
enum_type_e mVariable;
};


I supposed it's possible he was going to add more to the structure, but after looking at how it is used, I don't think so.

Barring "he was going to add more to the structure," why package a single enum in a struct? Is there some motivation I'm not thinking of?

**Update:**

As asked in the comments, he used it in this fashion:

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

This was originally built with GCC 3.3.5 if it makes any difference.
Reply

#2
Are there other structs with the same type of member first but different otherwise? He might be using the `struct thing_type_data_s` in a baseclass-y kind of way. But who knows, you tagged the question as both C and C++. I would make sense in C, at least.
Reply

#3
Possibly to enforce some type safety. Old-style enums are implicitly convertible to integral types, and this is not always desirable. Besides this, they are unscoped.

C++11 adds scoped enumerations (or "class" enums) to fix both of these issues.

Here's an example:

void foo(int) {}

int main()
{
foo(OPTION_A); // OK
thing_type_data_s s = { OPTION_A };
foo(s); // Error
}

Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through