How do I go through an enumeration consistently? - page 6

 
pavlick_:

A note to programmers:


Now if we need to edit an enumeration, we edit once and in one place. We need to add a new element, for example element_new = 56, we add

And we don't bother editing function get_enumqq_array(). The technique is called X Macro https://en.wikipedia.org/wiki/X_Macro. If developers wish, they can easily modify standard enumerations in a similar way.

Maybe not immediately obvious, the enumeration turned out this way:

Cool! I didn't know about the X Macro, thank you! I just do not understand the code, why there is no error because of the comma at the end of definition ENUM_QQ_HELPER. There should not be a comma after the last element when defining enum or array. But the compiler doesn't seem to swear at it for some reason.

I tried

int a[] = {1, 2,};

it won't. And the array size (enum) is as it should be. It's cool! It seems to be a bug, but I'd rather have such a bug. Really, it is convenient.

 
why there is no error due to a comma

Well, it's a legitimate violation, especially for all sorts of "stuff" like this, apparently. Don't worry about it, it's not an error in C/C++ either.

SZZ: in C++ standard on the subject of initialization:

braced-init-list:

   {initializer-list , opt}

   { }

I.e. the comma at the end of braced-init-list is legalised at the highest level.

 
pavlick_:

That is, the comma at the end of the braced-init-list is legalised at the highest level.

Thank you, I will know and use it.
 
pavlick_:

A note to programmers:

What about the normal names that are in the comments?

 
Комбинатор:

What about the normal names that are in the comments?

Can I have an example of the enum in question?
 
Комбинатор:

What about the normal names that are in the comments?

Yes, inserting a comment doesn't work. Unfortunate syntax for commenting on enums.

Can I have an example of the enum in question?

enum E
{
   a = 1         // вот этот комментарий
}
 
pavlick_:

Yes, it doesn't work to insert a comment. Unfortunate syntax for commenting on enumerations.

Conclude it with /*...*/.
 
fxsaber:
Conclude it in /*...*/.
The nonsense here is that the preprocessor does not want to eat comments (both // and /*), does not expect to see them when expanding macros. Either change the rules for preprocessor, or introduce an alternative way to comment enumerations (comment will be displayed when running the script in settings), such as this:

enum E {
   a = 1,            --**--  Комментарий_1
   b = 2            --**--  Комментарий_2
};
I'm already powerless here.
 
pavlick_:
The thing here is that the preprocessor doesn't want to eat comments (both // and /*), it doesn't expect to see them when macros are expanded. Either change the rules for preprocessor, or introduce alternative way to comment enumerations (comment will be displayed when running the script in settings), like this:

enum E {
   a = 1,            --**--  Комментарий_1
   b = 2            --**--  Комментарий_2
};
I'm already powerless here.
 

Preprocessing is done in several steps. At first, all comments are removed from the source code and the result is sent for processing. And this is where the preprocessor does not expect to encounter a comment (when it opens the macros). It will consider such an encounter as an error. For example, here:

#define  COMMENT / ## /

void OnStart()
{
  COMMENT
}
At first sight, this harmless code should contain a comment. But it won't compile.
Reason: