cURL / Mailing Lists / curl-library / Single Mail

curl-library

## macro operator

From: jonatan <jonatan_at_wineasy.se>
Date: Thu, 4 Apr 2002 00:54:49 +0200

<curl/curl.h> uses the ## macro operator, which was introduced with
iso c. when compiling
a libcurl app with "cc -traditional ..." that includes <curl/curl.h>
you get the
following errors:

/usr/local/include/curl/curl.h:190: parse error before `#'
/usr/local/include/curl/curl.h:193: redefinition of `CURLOPT_'
/usr/local/include/curl/curl.h:190: `CURLOPT_' previously defined here
...
/usr/local/include/curl/curl.h:563: parse error before `#'
/usr/local/include/curl/curl.h:566: redefinition of `CURLFORM_'
/usr/local/include/curl/curl.h:563: `CURLFORM_' previously defined here
...

i got rid of the second part of that by changing the definition of CFINIT in
<curl/curl.h> to:

/* The macro "##" requires ISO C, so we fake it for pre-ISO C. */
#ifdef __STDC__
#define CFINIT(name) CURLFORM_ ## name
#else
#define CFINIT(name) CURLFORM_/**/name
#endif

which seems to work (at least with my darwin-5.3 compiler). changing CINIT was
slightly more difficult since:

/* The macro "##" requires ISO C, so we fake it for pre-ISO C. */
#ifdef __STDC__
#define CINIT(name,type,number) CURLOPT_ ## name = CURLOPTTYPE_ ##
type + number
#else
#define CINIT(name,type,number) CURLOPT_/**/name =
CURLOPTTYPE_/**/type + number
#endif

didn't work (don't know why). so i changed it to:

/* The macro "##" requires ISO C, so we fake it for pre-ISO C. */
#ifdef __STDC__
#define CINIT(name,type,number) CURLOPT_ ## name = CURLOPTTYPE_ ##
type + number
#else
#define LONG 0
#define OBJECTPOINT 10000
#define FUNCTIONPOINT 20000
#define CINIT(name,type,number) CURLOPT_/**/name = type + number
#endif

which is less elegant but makes my app compile without errors, even
with "-traditional".

perhaps something along these lines can be incorporated into future releases of
curl?
Received on 2002-04-04