R
R Pradeep Chandran
Hi All,
Short version:
Is it possible to write macros to expand the following
DATAGROUP(abc)
ELEMENT(xyz)
ENDDATAGROUP
to
enum dg_abc {
el_abc_xyz,
};
using macro definitions that comply with the ISO standard?
Long version:
I have a set of legacy code which I have to modify and it uses a set of
macros as shown below to generate some data types and data structures.
DATAGROUP(abc)
ELEMENT(xyz)
ENDDATAGROUP
One of the data types generated will be an enumeration. For the above
example, it will be
enum dg_abc {
el_xyz,
};
So far, everything works OK. Till now, there was only one data group and
the element names are unique. Now, there is a need to add more than one
data group with the option to use the same element name in more than one
data group. As an example,
DATAGROUP(abc)
ELEMENT(xyz)
ENDDATAGROUP
DATAGROUP(def)
ELEMENT(xyz)
ENDDATAGROUP
The problem is that with the current macros, the types will be generated
as below.
enum dg_abc {
el_xyz,
};
enum dg_def {
el_xyz,
};
This will result in a compilation error. It would be great if I can avoid
this by prefixing the name of the data group to the enumeration constants
as shown in the short version of the question. Any ideas?
If something like this doesn't work, I am planning to redesign the
configuration macros. But, this would mean changing a lot of existing code
and I would prefer to avoid that.
Have a great day,
Pradeep
Short version:
Is it possible to write macros to expand the following
DATAGROUP(abc)
ELEMENT(xyz)
ENDDATAGROUP
to
enum dg_abc {
el_abc_xyz,
};
using macro definitions that comply with the ISO standard?
Long version:
I have a set of legacy code which I have to modify and it uses a set of
macros as shown below to generate some data types and data structures.
DATAGROUP(abc)
ELEMENT(xyz)
ENDDATAGROUP
One of the data types generated will be an enumeration. For the above
example, it will be
enum dg_abc {
el_xyz,
};
So far, everything works OK. Till now, there was only one data group and
the element names are unique. Now, there is a need to add more than one
data group with the option to use the same element name in more than one
data group. As an example,
DATAGROUP(abc)
ELEMENT(xyz)
ENDDATAGROUP
DATAGROUP(def)
ELEMENT(xyz)
ENDDATAGROUP
The problem is that with the current macros, the types will be generated
as below.
enum dg_abc {
el_xyz,
};
enum dg_def {
el_xyz,
};
This will result in a compilation error. It would be great if I can avoid
this by prefixing the name of the data group to the enumeration constants
as shown in the short version of the question. Any ideas?
If something like this doesn't work, I am planning to redesign the
configuration macros. But, this would mean changing a lot of existing code
and I would prefer to avoid that.
Have a great day,
Pradeep