xmlbeansxx icon indicating copy to clipboard operation
xmlbeansxx copied to clipboard

Compiling error when macro defined

Open Vanuan opened this issue 14 years ago • 6 comments

I have a shema that includes enum values which has the same names as macro defines.

<xsd:simpleType name="ST_Example">
<xsd:restriction base="xsd:token">
  <xsd:enumeration value="macro1">
  </xsd:enumeration>
  <xsd:enumeration value="macro2">
  </xsd:enumeration>
  <xsd:enumeration value="macro3">
  </xsd:enumeration>
</xsd:restriction>
 </xsd:simpleType>

It generates to:

static const Enum MACRO1;
static const Enum MACRO2;
static const Enum MACRO3;

When compiler finds MACRO1 it substitutes it.

So, I have three options: rename name in schema rename macro write #undef MACRO1 before variable declaration.

The best option, I think, is the third. How can I change generator, so it will add "#undef MACRO1" before "static const Enum MACRO1"?

Vanuan avatar Oct 04 '11 23:10 Vanuan

the best solution is number 2 ;) you should never give such a name to a macro. A macros should be prefixed with something like a namespace. for example our marcos have: XMLBEANSXX_ as a prefix, boost has BOOST_ log4cxx has LOG4CXX_

(microsoft macros do not count ;) )

unfortunately there is no simple possibility to change the generator, you can only change the generated code.

or there is a fourth solution: before you include you header you can undefine the marco:

#undefine MACRO1 #include "ST_example.h"

2011/10/5 John Yani < [email protected]>

I have a shema that includes enum values which has the same names as macro defines.

<xsd:simpleType name="ST_Example"> <xsd:restriction base="xsd:token"> <xsd:enumeration value="macro1"> /xsd:enumeration <xsd:enumeration value="macro2"> /xsd:enumeration <xsd:enumeration value="macro3"> /xsd:enumeration /xsd:restriction /xsd:simpleType

It generates to:

static const Enum MACRO1; static const Enum MACRO2; static const Enum MACRO3;

When compiler finds MACRO1 it substitutes it. So, I have three options: rename name in schema, rename macro definition, or write #undef MACRO1 before variable declaration. The best option, I think, is the third. How can I change generator, so it will add "#undef MACRO1" before "static const Enum MACRO1"?

Reply to this email directly or view it on GitHub: https://github.com/rafalrusin/xmlbeansxx/issues/6

stawel avatar Oct 05 '11 09:10 stawel

The problem is that macros is in math.h It is not prefixed with M, and fourth option doesn't help. 05.10.2011 12:34 "stawel" < [email protected]> :

the best solution is number 2 ;) you should never give such a name to a macro. A macros should be prefixed with something like a namespace. for example our marcos have: XMLBEANSXX_ as a prefix, boost has BOOST_ log4cxx has LOG4CXX_

(microsoft macros do not count ;) )

unfortunately there is no simple possibility to change the generator, you can only change the generated code.

or there is a fourth solution: before you include you header you can undefine the marco:

#undefine MACRO1 #include "ST_example.h"

2011/10/5 John Yani < [email protected]>

I have a shema that includes enum values which has the same names as macro defines.

<xsd:simpleType name="ST_Example"> <xsd:restriction base="xsd:token"> <xsd:enumeration value="macro1"> /xsd:enumeration <xsd:enumeration value="macro2"> /xsd:enumeration <xsd:enumeration value="macro3"> /xsd:enumeration /xsd:restriction /xsd:simpleType

It generates to:

static const Enum MACRO1; static const Enum MACRO2; static const Enum MACRO3;

When compiler finds MACRO1 it substitutes it. So, I have three options: rename name in schema, rename macro definition, or write #undef MACRO1 before variable declaration. The best option, I think, is the third. How can I change generator, so it will add "#undef MACRO1" before "static const Enum MACRO1"?

Reply to this email directly or view it on GitHub: https://github.com/rafalrusin/xmlbeansxx/issues/6

Reply to this email directly or view it on GitHub: https://github.com/rafalrusin/xmlbeansxx/issues/6#issuecomment-2296151

Vanuan avatar Oct 05 '11 17:10 Vanuan

surprising :)

what system are you using ? can you attach the math.h ?

probably you can add the undef at the end of the xmlbeansxx.h file.

stawel avatar Oct 05 '11 21:10 stawel

I'm using ubuntu. Here's the snippet from math.h causing problems:

/* Types of exceptions in the `type' field.  */
# define DOMAIN     1
# define SING       2
# define OVERFLOW   3
# define UNDERFLOW  4
# define TLOSS      5
# define PLOSS      6


/* SVID mode specifies returning this large value instead of infinity.  */
# define HUGE       3.40282347e+38F

As you can see, I can't use a bunch of names as enum values in my schema.

Vanuan avatar Oct 05 '11 21:10 Vanuan

I thought that there really is a macro called MACRO1 :)

2011/10/5 John Yani < [email protected]>

I'm using ubuntu. Here's the snippet from math.h causing problems:

/* Types of exceptions in the `type' field. */

define DOMAIN 1

define SING 2

define OVERFLOW 3

define UNDERFLOW 4

define TLOSS 5

define PLOSS 6

/* SVID mode specifies returning this large value instead of infinity. */

define HUGE 3.40282347e+38F

As you can see, I can't use a bunch of names as enum values in my schema.

Reply to this email directly or view it on GitHub: https://github.com/rafalrusin/xmlbeansxx/issues/6#issuecomment-2303597

stawel avatar Oct 05 '11 21:10 stawel

No, it was just an example :)

Vanuan avatar Oct 05 '11 21:10 Vanuan