digitalmars.D.learn - C header file: tagged enumerations
- Jesse Phillips (25/25) Apr 26 2016 Windows tends to have these in their header files, what is the
- Stefan Koch (3/6) Apr 26 2016 eunm win32msi = mixin(_WIN32_MSI);
- Jesse Phillips (5/12) Apr 26 2016 Sorry forgot to mention that static if doesn't allow adding
- Adam D. Ruppe (8/9) Apr 26 2016 Won't work here because static if must have a complete
- Steven Schveighoffer (6/15) Apr 27 2016 Hm... doesn't the way the enumeration assigns values mean that on older
- Jesse Phillips (22/25) Apr 28 2016 Yeah, I didn't even consider that different versions have
- Jesse Phillips (3/19) Apr 28 2016 FYI, that is a no since attributes can't be added to enumerations.
- BLM768 (5/7) Apr 27 2016 Or you can use the technique that's used in llvm-d: build the
- Max Samukha (18/35) Apr 27 2016 enum _WIN32_MSI = 450;
- Kagamin (17/17) Apr 28 2016 enum
- Jesse Phillips (7/24) Apr 28 2016 This one doesn't get the values right for the different versions.
- Kagamin (25/31) Apr 29 2016 Different values depending on target version? That's weird, never
Windows tends to have these in their header files, what is the best way to translate them to D? https://msdn.microsoft.com/en-us/library/whbyts4t.aspx Example below. In general a named enum is close enough to the same thing, but this example has additional enumerations added based on the preprocessor. Assuming _WIN32_MSI is defined for compile time, what is recommended for creating this enum? typedef enum tagINSTALLMESSAGE { // 12 others ... INSTALLMESSAGE_INITIALIZE , INSTALLMESSAGE_TERMINATE , INSTALLMESSAGE_SHOWDIALOG , #if (_WIN32_MSI >= 500) INSTALLMESSAGE_PERFORMANCE , #endif // (_WIN32_MSI >= 500) #if (_WIN32_MSI >= 400) INSTALLMESSAGE_RMFILESINUSE , #endif // (_WIN32_MSI >= 400) #if (_WIN32_MSI >= 450) INSTALLMESSAGE_INSTALLSTART , INSTALLMESSAGE_INSTALLEND , #endif // (_WIN32_MSI >= 450) } INSTALLMESSAGE;
Apr 26 2016
On Tuesday, 26 April 2016 at 22:57:36 UTC, Jesse Phillips wrote:Windows tends to have these in their header files, what is the best way to translate them to D? [...]eunm win32msi = mixin(_WIN32_MSI); static if (win32msi >= 500) .....
Apr 26 2016
On Tuesday, 26 April 2016 at 23:33:08 UTC, Stefan Koch wrote:On Tuesday, 26 April 2016 at 22:57:36 UTC, Jesse Phillips wrote:Sorry forgot to mention that static if doesn't allow adding partial declarations, always need to be complete. Or to quote the compiler: "Error: basic type expected, not static"Windows tends to have these in their header files, what is the best way to translate them to D? [...]eunm win32msi = mixin(_WIN32_MSI); static if (win32msi >= 500) .....
Apr 26 2016
On Tuesday, 26 April 2016 at 23:33:08 UTC, Stefan Koch wrote:static if (win32msi >= 500) .....Won't work here because static if must have a complete declaration inside it, and the C pattern only has a few elements of the whole inside each #if. D doesn't handle this C pattern well... you basically have to rewrite the whole thing for each version. Personally, I just decide to support all of them and say the older versions with less declarations are less supported...
Apr 26 2016
On 4/26/16 7:40 PM, Adam D. Ruppe wrote:On Tuesday, 26 April 2016 at 23:33:08 UTC, Stefan Koch wrote:Hm... doesn't the way the enumeration assigns values mean that on older systems, the values would change for the same symbols? BTW, this enumeration looks terrible. I would flag this as blocking if it were a code review, even in C++. -Stevestatic if (win32msi >= 500) .....Won't work here because static if must have a complete declaration inside it, and the C pattern only has a few elements of the whole inside each #if. D doesn't handle this C pattern well... you basically have to rewrite the whole thing for each version. Personally, I just decide to support all of them and say the older versions with less declarations are less supported...
Apr 27 2016
On Wednesday, 27 April 2016 at 16:04:13 UTC, Steven Schveighoffer wrote:BTW, this enumeration looks terrible. I would flag this as blocking if it were a code review, even in C++. -SteveYeah, I didn't even consider that different versions have different enum values; that is going to be a really good way to break backwards compatibility. Hmm, I wonder if I can make use of UDA and a mixin something like enum tagINSTALLMESSAGE { // 12 others ... INSTALLMESSAGE_INITIALIZE , INSTALLMESSAGE_TERMINATE , INSTALLMESSAGE_SHOWDIALOG , [greaterThan(500)] INSTALLMESSAGE_PERFORMANCE , [greaterThan(400)] INSTALLMESSAGE_RMFILESINUSE , [greaterThan(450)] INSTALLMESSAGE_INSTALLSTART , [greaterThan(450)] INSTALLMESSAGE_INSTALLEND , } mixin taggedEnum!tagINSTALLMESSAGE
Apr 28 2016
On Thursday, 28 April 2016 at 17:40:23 UTC, Jesse Phillips wrote:enum tagINSTALLMESSAGE { // 12 others ... INSTALLMESSAGE_INITIALIZE , INSTALLMESSAGE_TERMINATE , INSTALLMESSAGE_SHOWDIALOG , [greaterThan(500)] INSTALLMESSAGE_PERFORMANCE , [greaterThan(400)] INSTALLMESSAGE_RMFILESINUSE , [greaterThan(450)] INSTALLMESSAGE_INSTALLSTART , [greaterThan(450)] INSTALLMESSAGE_INSTALLEND , } mixin taggedEnum!tagINSTALLMESSAGEFYI, that is a no since attributes can't be added to enumerations. "Error: basic type expected, not "
Apr 28 2016
On Tuesday, 26 April 2016 at 23:40:24 UTC, Adam D. Ruppe wrote:D doesn't handle this C pattern well... you basically have to rewrite the whole thing for each version.Or you can use the technique that's used in llvm-d: build the enumeration from a string mixin which is generated from a table. It's not necessarily the most elegant solution, but it can eliminate some code duplication.
Apr 27 2016
On Tuesday, 26 April 2016 at 22:57:36 UTC, Jesse Phillips wrote:typedef enum tagINSTALLMESSAGE { // 12 others ... INSTALLMESSAGE_INITIALIZE , INSTALLMESSAGE_TERMINATE , INSTALLMESSAGE_SHOWDIALOG , #if (_WIN32_MSI >= 500) INSTALLMESSAGE_PERFORMANCE , #endif // (_WIN32_MSI >= 500) #if (_WIN32_MSI >= 400) INSTALLMESSAGE_RMFILESINUSE , #endif // (_WIN32_MSI >= 400) #if (_WIN32_MSI >= 450) INSTALLMESSAGE_INSTALLSTART , INSTALLMESSAGE_INSTALLEND , #endif // (_WIN32_MSI >= 450) } INSTALLMESSAGE;enum _WIN32_MSI = 450; mixin((int _WIN32_MSI = _WIN32_MSI) { string r ="enum INSTALLMESSAGE { INSTALLMESSAGE_INITIALIZE, INSTALLMESSAGE_TERMINATE, INSTALLMESSAGE_SHOWDIALOG,"; if (_WIN32_MSI >= 500) r ~= "INSTALLMESSAGE_PERFORMANCE ,"; if (_WIN32_MSI >= 400) r ~= "INSTALLMESSAGE_RMFILESINUSE ,"; if (_WIN32_MSI >= 450) { r ~= "INSTALLMESSAGE_INSTALLSTART , INSTALLMESSAGE_INSTALLEND ,"; } return r ~ "}"; }()); ))) // sardonic laugh, which is not part of the source
Apr 27 2016
enum { // 12 others ... INSTALLMESSAGE_INITIALIZE , INSTALLMESSAGE_TERMINATE , INSTALLMESSAGE_SHOWDIALOG } static if(_WIN32_MSI >= 500) enum INSTALLMESSAGE_PERFORMANCE=15; static if(_WIN32_MSI >= 400) enum INSTALLMESSAGE_RMFILESINUSE=16; static if(_WIN32_MSI >= 450) enum { INSTALLMESSAGE_INSTALLSTART=17, INSTALLMESSAGE_INSTALLEND }
Apr 28 2016
On Thursday, 28 April 2016 at 08:54:45 UTC, Kagamin wrote:enum { // 12 others ... INSTALLMESSAGE_INITIALIZE , INSTALLMESSAGE_TERMINATE , INSTALLMESSAGE_SHOWDIALOG } static if(_WIN32_MSI >= 500) enum INSTALLMESSAGE_PERFORMANCE=15; static if(_WIN32_MSI >= 400) enum INSTALLMESSAGE_RMFILESINUSE=16; static if(_WIN32_MSI >= 450) enum { INSTALLMESSAGE_INSTALLSTART=17, INSTALLMESSAGE_INSTALLEND }This one doesn't get the values right for the different versions. The other problem is functions are written as: void* something(INSTALLMESSAGE arg); So I could make all the functions take an int/uint or such, but that is a lot of change for the header along with less documenting.
Apr 28 2016
On Thursday, 28 April 2016 at 22:54:10 UTC, Jesse Phillips wrote:This one doesn't get the values right for the different versions. The other problem is functions are written as: void* something(INSTALLMESSAGE arg); So I could make all the functions take an int/uint or such, but that is a lot of change for the header along with less documenting.Different values depending on target version? That's weird, never seen anything like that in windows headers. enum { // 12 others ... INSTALLMESSAGE_INITIALIZE , INSTALLMESSAGE_TERMINATE , INSTALLMESSAGE_SHOWDIALOG } static if(_WIN32_MSI >= 500) enum { INSTALLMESSAGE_PERFORMANCE=15, INSTALLMESSAGE_RMFILESINUSE } else static if(_WIN32_MSI >= 400) enum INSTALLMESSAGE_RMFILESINUSE=15; static if(_WIN32_MSI >= 450) enum { INSTALLMESSAGE_INSTALLSTART=INSTALLMESSAGE_RMFILESINUSE+1, INSTALLMESSAGE_INSTALLEND } alias INSTALLMESSAGE=int;
Apr 29 2016