www.digitalmars.com         C & C++   DMDScript  

c++ - Problem with enums and preprocessor

reply "Charles Sanders" <sanders-consulting comcast.net> writes:
Still trying to port libcurl, lots of enums ill give to shorten examples

typedef enum {
  CURLOPT_NOTHING = 0,
   CURLOPT_FOO = 202
} CURLoption;

This produces :

../include\curl/curl.h(684) : Error: 'CURLOPT_NOTHING' is already defined

This is the only place CURLOPT_NOTHING is even mentioned

I get the same results using a regular enum

enum {

CURLOPT_FOO = 202
}


Whats up ?  It also seems the preprocessor stumbles alot on the macros, we
have this

#define CINIT(name,type,number) CURLOPT_ ## name = CURLOPTTYPE_ ## type +
number

typedef enum {
  CURLOPT_NOTHING = 0,

  /* This is the FILE * or void * the regular output should be written to.
*/
  CINIT(FILE, OBJECTPOINT, 1),

  /* The full URL to get/put */
  CINIT(URL,  OBJECTPOINT, 2),

  /* Port number to connect to, if other than default. */
  CINIT(PORT, LONG, 3),

  /* Name of proxy to use. */
  CINIT(PROXY, OBJECTPOINT, 4),

...

So far I have had to change all these by hands ( or with a short script )
but Im wondering why this is not supported ?

Thanks
Charles
Sep 20 2003
next sibling parent "Gisle Vanem" <giva users.sourceforge.net> writes:
"Charles Sanders" <sanders-consulting comcast.net> wrote:

 #define CINIT(name,type,number) CURLOPT_ ## name = CURLOPTTYPE_ ## type +
 number

 typedef enum {
   CURLOPT_NOTHING = 0,

   /* This is the FILE * or void * the regular output should be written to.
 */
   CINIT(FILE, OBJECTPOINT, 1),

   /* The full URL to get/put */
   CINIT(URL,  OBJECTPOINT, 2),

   /* Port number to connect to, if other than default. */
   CINIT(PORT, LONG, 3),

   /* Name of proxy to use. */
   CINIT(PROXY, OBJECTPOINT, 4),

 ...

 So far I have had to change all these by hands ( or with a short script )
 but Im wondering why this is not supported ?

Because, I think DMC's preprocessor isn't fully ISO compatible. It has problems with the paste operator (##) and the above macro. Try to patch curl.h: #if (defined(__STDC__) || defined(_MSC_VER) || defined(__cplusplus) || \ defined(__HP_aCC) || defined(__BORLANDC__)) && !defined(__DMC__) /* This compiler is believed to have an ISO compatible preprocessor */ #define CURL_ISOCPP #else --gv
Sep 21 2003
prev sibling parent reply "Walter" <walter digitalmars.com> writes:
"Charles Sanders" <sanders-consulting comcast.net> wrote in message
news:bkj5b0$jqe$1 digitaldaemon.com...
 Still trying to port libcurl, lots of enums ill give to shorten examples

 typedef enum {
   CURLOPT_NOTHING = 0,
    CURLOPT_FOO = 202
 } CURLoption;

 This produces :

 ../include\curl/curl.h(684) : Error: 'CURLOPT_NOTHING' is already defined

 This is the only place CURLOPT_NOTHING is even mentioned

Try deleting code prior to the error message until the error goes away, to see what causes it. The CINIT macro must be generating another CURLOPT_NOTHING earlier in the source text.
  It also seems the preprocessor stumbles alot on the macros, we
 have this

 #define CINIT(name,type,number) CURLOPT_ ## name = CURLOPTTYPE_ ## type +
 number

The following code: ----------------------------------- #define CINIT(name,type,number) CURLOPT_ ## name = CURLOPTTYPE_ ## type + number int CURLOPT_foo; int CURLOPTTYPE_bar; void test() { CINIT(foo,bar,57); } ----------------------------------- compiles and generates the expected code.
 So far I have had to change all these by hands ( or with a short script )
 but Im wondering why this is not supported ?

There must be something else happening in the code you're using outside of the examples you posted.
Sep 21 2003
parent reply "Charles Sanders" <sanders-consulting comcast.net> writes:
Odly, if i use a file with .cpp extension, the header problems go away.  Ill
try to build it forcing the compiler to use CPP.

Thanks,
C
"Walter" <walter digitalmars.com> wrote in message
news:bkkpt5$sr6$1 digitaldaemon.com...
 "Charles Sanders" <sanders-consulting comcast.net> wrote in message
 news:bkj5b0$jqe$1 digitaldaemon.com...
 Still trying to port libcurl, lots of enums ill give to shorten examples

 typedef enum {
   CURLOPT_NOTHING = 0,
    CURLOPT_FOO = 202
 } CURLoption;

 This produces :

 ../include\curl/curl.h(684) : Error: 'CURLOPT_NOTHING' is already


 This is the only place CURLOPT_NOTHING is even mentioned

Try deleting code prior to the error message until the error goes away, to see what causes it. The CINIT macro must be generating another CURLOPT_NOTHING earlier in the source text.
  It also seems the preprocessor stumbles alot on the macros, we
 have this

 #define CINIT(name,type,number) CURLOPT_ ## name = CURLOPTTYPE_ ## type


 number

The following code: ----------------------------------- #define CINIT(name,type,number) CURLOPT_ ## name = CURLOPTTYPE_ ## type + number int CURLOPT_foo; int CURLOPTTYPE_bar; void test() { CINIT(foo,bar,57); } ----------------------------------- compiles and generates the expected code.
 So far I have had to change all these by hands ( or with a short


 but Im wondering why this is not supported ?

There must be something else happening in the code you're using outside of the examples you posted.

Sep 22 2003
parent "Charles Sanders" <sanders-consulting comcast.net> writes:
This unfortunately brings about other issues (using names like private,
protected ), I tried just compiling the DLL with VC6 ( this is all to create
D wrappers for libcurl ) using implib on the def file which works but I get
runtime errors ( failed to initalize ).  I hope SWIG gets completed soon
(couldnt find an executable ).

C
"Charles Sanders" <sanders-consulting comcast.net> wrote in message
news:bknr9o$2sgf$1 digitaldaemon.com...
 Odly, if i use a file with .cpp extension, the header problems go away.

 try to build it forcing the compiler to use CPP.

 Thanks,
 C
 "Walter" <walter digitalmars.com> wrote in message
 news:bkkpt5$sr6$1 digitaldaemon.com...
 "Charles Sanders" <sanders-consulting comcast.net> wrote in message
 news:bkj5b0$jqe$1 digitaldaemon.com...
 Still trying to port libcurl, lots of enums ill give to shorten



 typedef enum {
   CURLOPT_NOTHING = 0,
    CURLOPT_FOO = 202
 } CURLoption;

 This produces :

 ../include\curl/curl.h(684) : Error: 'CURLOPT_NOTHING' is already


 This is the only place CURLOPT_NOTHING is even mentioned

Try deleting code prior to the error message until the error goes away,


 see what causes it. The CINIT macro must be generating another
 CURLOPT_NOTHING earlier in the source text.

  It also seems the preprocessor stumbles alot on the macros, we
 have this

 #define CINIT(name,type,number) CURLOPT_ ## name = CURLOPTTYPE_ ##



 +
 number

The following code: ----------------------------------- #define CINIT(name,type,number) CURLOPT_ ## name = CURLOPTTYPE_ ## type


 number

 int CURLOPT_foo;
 int CURLOPTTYPE_bar;

 void test()
 {
     CINIT(foo,bar,57);
 }
 -----------------------------------
 compiles and generates the expected code.

 So far I have had to change all these by hands ( or with a short


 but Im wondering why this is not supported ?

There must be something else happening in the code you're using outside


 the examples you posted.


Sep 22 2003