rafalrusin / xmlbeansxx

xmlbeansxx is an open source C++ library easing the processing of XML data. It is very similar to and in fact was inspired by Apache XMLBeans. The goal is to have the same functionalities and interfaces of XMLBeans.
http://xmlbeansxx.touk.pl
Apache License 2.0
18 stars 8 forks source link

Compiling error when macro defined #6

Open Vanuan opened 13 years ago

Vanuan commented 13 years ago

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"?

stawel commented 13 years ago

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 < reply@reply.github.com>

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

/xsd:enumeration /xsd:enumeration /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
Vanuan commented 13 years ago

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" < reply@reply.github.com> :

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 < reply@reply.github.com>

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

/xsd:enumeration /xsd:enumeration /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

stawel commented 13 years ago

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.

Vanuan commented 13 years ago

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.

stawel commented 13 years ago

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

2011/10/5 John Yani < reply@reply.github.com>

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

Vanuan commented 13 years ago

No, it was just an example :)