Hi,

I'm trying to use a program, written by others, that has C/C++ code compiled as part of its setup procedure (it's called Content - integrated environment for the analysis of dynamical systems). However, c++ (or g++ actually) complains about invalid conversions and cannot compile:

autodif.c: In function ‘char* Mult(char*, char*, char)’:
autodif.c:509: error: invalid conversion from ‘const char*’ to ‘char*’
autodif.c: In function ‘char* Sub(char*, char*, char)’:
autodif.c:659: error: invalid conversion from ‘const char*’ to ‘char*’
autodif.c:668: error: invalid conversion from ‘const char*’ to ‘char*’
autodif.c: In function ‘char* Div(char*, char*, char)’:
autodif.c:753: error: invalid conversion from ‘const char*’ to ‘char*’
autodif.c: In function ‘char* rel(char*, char*, char*, int)’:
autodif.c:1609: error: invalid conversion from ‘const char*’ to ‘char*’
autodif.c: In function ‘char* GetExpr_(const Gradient&)’:
autodif.c:1872: error: invalid conversion from ‘const char*’ to ‘char*’
autodif.c: In function ‘char* GetDer1_(const Gradient&, int)’:
autodif.c:1888: error: invalid conversion from ‘const char*’ to ‘char*’
autodif.c: In function ‘char* GetDer2_(const Gradient&, int, int)’:
autodif.c:1904: error: invalid conversion from ‘const char*’ to ‘char*’
autodif.c: In function ‘char* GetDer3_(const Gradient&, int, int, int)’:
autodif.c:1921: error: invalid conversion from ‘const char*’ to ‘char*’

It's unlikely that the authors made a mistake and distributed the software without noticing it, so probably I'm missing something. But what? How do I find out?

Any suggestion is welcome. :)

Recommended Answers

All 7 Replies

the file you are trying to compile it is a C (not C++) file. compile that with gcc, not g++. in your C++ code include the header as follows:

extern "C"
{
  #include "whatever.h"
}

Thanks for replying, Vijayan.

I did as you suggested, but got more errors. I have three files: autodif.cc, autodif.c and autodif.h (see below).
I tried adding extern "C" { ... } in the .cc as you suggested, only where the .h is introduced, both where .h and .c are introduced and only where the .c is introduced but I got more errors. It's still complaining about invalid conversions, and I get errors about conflicting function declarations.

Note that the .c and the .cc have classes, so should be C++, right?

I'm fine with changing source code if it helps, but there should be other solutions...

$g++ -o autodif -O2 -fPIC -lc -lm autodif.cc 
autodif.h: In function ‘Gradient operator+(const Gradient&, const Gradient&)’:
autodif.h:44: error: previous declaration of ‘Gradient operator+(const Gradient&, const Gradient&)’ with ‘C++’ linkage
autodif.c:350: error: conflicts with new declaration with ‘C’ linkage
autodif.h: In function ‘Gradient operator+(const Gradient&, double)’:
autodif.h:45: error: previous declaration of ‘Gradient operator+(const Gradient&, double)’ with ‘C++’ linkage
autodif.c:373: error: conflicts with new declaration with ‘C’ linkage
autodif.h: In function ‘Gradient operator+(double, const Gradient&)’:
autodif.h:46: error: previous declaration of ‘Gradient operator+(double, const Gradient&)’ with ‘C++’ linkage
autodif.c:379: error: conflicts with new declaration with ‘C’ linkage
autodif.h: In function ‘Gradient operator+(const Gradient&, int)’:
autodif.h:47: error: previous declaration of ‘Gradient operator+(const Gradient&, int)’ with ‘C++’ linkage
autodif.c:385: error: conflicts with new declaration with ‘C’ linkage
autodif.h: In function ‘Gradient operator+(int, const Gradient&)’:
autodif.h:48: error: previous declaration of ‘Gradient operator+(int, const Gradient&)’ with ‘C++’ linkage
autodif.c:391: error: conflicts with new declaration with ‘C’ linkage
autodif.c: In function ‘char* Mult(char*, char*, char)’:
autodif.c:509: error: invalid conversion from ‘const char*’ to ‘char*’
autodif.h: In function ‘Gradient operator*(const Gradient&, const Gradient&)’:
autodif.h:50: error: previous declaration of ‘Gradient operator*(const Gradient&, const Gradient&)’ with ‘C++’ linkage
autodif.c:529: error: conflicts with new declaration with ‘C’ linkage
autodif.h: In function ‘Gradient operator*(const Gradient&, double)’:
autodif.h:51: error: previous declaration of ‘Gradient operator*(const Gradient&, double)’ with ‘C++’ linkage
autodif.c:624: error: conflicts with new declaration with ‘C’ linkage
autodif.h: In function ‘Gradient operator*(double, const Gradient&)’:
autodif.h:52: error: previous declaration of ‘Gradient operator*(double, const Gradient&)’ with ‘C++’ linkage
autodif.c:630: error: conflicts with new declaration with ‘C’ linkage
autodif.h: In function ‘Gradient operator*(const Gradient&, int)’:
autodif.h:53: error: previous declaration of ‘Gradient operator*(const Gradient&, int)’ with ‘C++’ linkage
autodif.c:636: error: conflicts with new declaration with ‘C’ linkage
autodif.h: In function ‘Gradient operator*(int, const Gradient&)’:
autodif.h:54: error: previous declaration of ‘Gradient operator*(int, const Gradient&)’ with ‘C++’ linkage
autodif.c:642: error: conflicts with new declaration with ‘C’ linkage
autodif.c: In function ‘char* Sub(char*, char*, char)’:
autodif.c:659: error: invalid conversion from ‘const char*’ to ‘char*’
autodif.c:668: error: invalid conversion from ‘const char*’ to ‘char*’
autodif.h: In function ‘Gradient operator-(const Gradient&, const Gradient&)’:
autodif.h:56: error: previous declaration of ‘Gradient operator-(const Gradient&, const Gradient&)’ with ‘C++’ linkage
autodif.c:689: error: conflicts with new declaration with ‘C’ linkage
autodif.h: In function ‘Gradient operator-(const Gradient&, double)’:
autodif.h:58: error: previous declaration of ‘Gradient operator-(const Gradient&, double)’ with ‘C++’ linkage
autodif.c:711: error: conflicts with new declaration with ‘C’ linkage
autodif.h: In function ‘Gradient operator-(const Gradient&)’:
autodif.h:57: error: previous declaration of ‘Gradient operator-(const Gradient&)’ with ‘C++’ linkage
autodif.c:717: error: conflicts with new declaration with ‘C’ linkage
autodif.h: In function ‘Gradient operator-(double, const Gradient&)’:
autodif.h:59: error: previous declaration of ‘Gradient operator-(double, const Gradient&)’ with ‘C++’ linkage
autodif.c:722: error: conflicts with new declaration with ‘C’ linkage
autodif.h: In function ‘Gradient operator-(const Gradient&, int)’:
autodif.h:60: error: previous declaration of ‘Gradient operator-(const Gradient&, int)’ with ‘C++’ linkage
autodif.c:728: error: conflicts with new declaration with ‘C’ linkage
autodif.h: In function ‘Gradient operator-(int, const Gradient&)’:
autodif.h:61: error: previous declaration of ‘Gradient operator-(int, const Gradient&)’ with ‘C++’ linkage
autodif.c:734: error: conflicts with new declaration with ‘C’ linkage
autodif.c: In function ‘char* Div(char*, char*, char)’:
autodif.c:753: error: invalid conversion from ‘const char*’ to ‘char*’
autodif.h: In function ‘Gradient operator/(const Gradient&, const Gradient&)’:
autodif.h:63: error: previous declaration of ‘Gradient operator/(const Gradient&, const Gradient&)’ with ‘C++’ linkage
autodif.c:772: error: conflicts with new declaration with ‘C’ linkage
autodif.h: In function ‘Gradient operator/(const Gradient&, double)’:
autodif.h:64: error: previous declaration of ‘Gradient operator/(const Gradient&, double)’ with ‘C++’ linkage
autodif.c:858: error: conflicts with new declaration with ‘C’ linkage
autodif.h: In function ‘Gradient operator/(double, const Gradient&)’:
autodif.h:65: error: previous declaration of ‘Gradient operator/(double, const Gradient&)’ with ‘C++’ linkage
autodif.c:864: error: conflicts with new declaration with ‘C’ linkage
autodif.h: In function ‘Gradient operator/(const Gradient&, int)’:
autodif.h:66: error: previous declaration of ‘Gradient operator/(const Gradient&, int)’ with ‘C++’ linkage
autodif.c:870: error: conflicts with new declaration with ‘C’ linkage
autodif.h: In function ‘Gradient operator/(int, const Gradient&)’:
autodif.h:67: error: previous declaration of ‘Gradient operator/(int, const Gradient&)’ with ‘C++’ linkage
autodif.c:875: error: conflicts with new declaration with ‘C’ linkage
autodif.h: In function ‘Gradient operator/(const Gradient&, int)’:
autodif.h:109: error: previous declaration of ‘Gradient fabs(const Gradient&)’ with ‘C++’ linkage
autodif.c:1265: error: conflicts with new declaration with ‘C’ linkage
autodif.h: In function ‘Gradient operator/(int, const Gradient&)’:
autodif.h:110: error: previous declaration of ‘Gradient exp(const Gradient&)’ with ‘C++’ linkage
autodif.c:1281: error: conflicts with new declaration with ‘C’ linkage
autodif.h: In function ‘Gradient operator/(const Gradient&, int)’:
autodif.h:111: error: previous declaration of ‘Gradient log(const Gradient&)’ with ‘C++’ linkage
autodif.c:1299: error: conflicts with new declaration with ‘C’ linkage
autodif.h: In function ‘Gradient operator/(int, const Gradient&)’:
autodif.h:112: error: previous declaration of ‘Gradient sqrt(const Gradient&)’ with ‘C++’ linkage
autodif.c:1322: error: conflicts with new declaration with ‘C’ linkage
autodif.h: In function ‘Gradient operator/(const Gradient&, int)’:
autodif.h:113: error: previous declaration of ‘Gradient pow(const Gradient&, double)’ with ‘C++’ linkage
autodif.c:1351: error: conflicts with new declaration with ‘C’ linkage
autodif.h: In function ‘Gradient operator/(int, const Gradient&)’:
autodif.h:114: error: previous declaration of ‘Gradient pow(const Gradient&, int)’ with ‘C++’ linkage
autodif.c:1399: error: conflicts with new declaration with ‘C’ linkage
autodif.h: In function ‘Gradient operator/(const Gradient&, int)’:
autodif.h:115: error: previous declaration of ‘Gradient pow(const Gradient&, const Gradient&)’ with ‘C++’ linkage
autodif.c:1403: error: conflicts with new declaration with ‘C’ linkage
autodif.h: In function ‘Gradient operator/(int, const Gradient&)’:
autodif.h:116: error: previous declaration of ‘Gradient sin(const Gradient&)’ with ‘C++’ linkage
autodif.c:1407: error: conflicts with new declaration with ‘C’ linkage
autodif.h: In function ‘Gradient operator/(const Gradient&, int)’:
autodif.h:117: error: previous declaration of ‘Gradient cos(const Gradient&)’ with ‘C++’ linkage
autodif.c:1433: error: conflicts with new declaration with ‘C’ linkage
autodif.h: In function ‘Gradient operator/(int, const Gradient&)’:
autodif.h:118: error: previous declaration of ‘Gradient tan(const Gradient&)’ with ‘C++’ linkage
autodif.c:1459: error: conflicts with new declaration with ‘C’ linkage
autodif.h: In function ‘Gradient operator/(const Gradient&, int)’:
autodif.h:121: error: previous declaration of ‘Gradient atan(const Gradient&)’ with ‘C++’ linkage
autodif.c:1487: error: conflicts with new declaration with ‘C’ linkage
autodif.h: In function ‘Gradient operator/(int, const Gradient&)’:
autodif.h:119: error: previous declaration of ‘Gradient asin(const Gradient&)’ with ‘C++’ linkage
autodif.c:1515: error: conflicts with new declaration with ‘C’ linkage
autodif.h: In function ‘Gradient operator/(const Gradient&, int)’:
autodif.h:120: error: previous declaration of ‘Gradient acos(const Gradient&)’ with ‘C++’ linkage
autodif.c:1545: error: conflicts with new declaration with ‘C’ linkage
autodif.h: In function ‘Gradient operator/(int, const Gradient&)’:
autodif.h:122: error: previous declaration of ‘Gradient iff(const Gradient&, const Gradient&, const Gradient&)’ with ‘C++’ linkage
autodif.c:1550: error: conflicts with new declaration with ‘C’ linkage
autodif.c: In function ‘Gradient operator/(const Gradient&, int)’:
autodif.c:1609: error: invalid conversion from ‘const char*’ to ‘char*’
autodif.h: In function ‘Gradient operator/(int, const Gradient&)’:
autodif.h:69: error: previous declaration of ‘Gradient operator>(const Gradient&, const Gradient&)’ with ‘C++’ linkage
autodif.c:1622: error: conflicts with new declaration with ‘C’ linkage
autodif.h:70: error: previous declaration of ‘Gradient operator>(const Gradient&, double)’ with ‘C++’ linkage
autodif.c:1629: error: conflicts with new declaration with ‘C’ linkage
autodif.h:71: error: previous declaration of ‘Gradient operator>(const Gradient&, int)’ with ‘C++’ linkage
autodif.c:1638: error: conflicts with new declaration with ‘C’ linkage
autodif.h:72: error: previous declaration of ‘Gradient operator>(double, const Gradient&)’ with ‘C++’ linkage
autodif.c:1643: error: conflicts with new declaration with ‘C’ linkage
autodif.h:73: error: previous declaration of ‘Gradient operator>(int, const Gradient&)’ with ‘C++’ linkage
autodif.c:1652: error: conflicts with new declaration with ‘C’ linkage
autodif.h:75: error: previous declaration of ‘Gradient operator>=(const Gradient&, const Gradient&)’ with ‘C++’ linkage
autodif.c:1657: error: conflicts with new declaration with ‘C’ linkage
autodif.h:76: error: previous declaration of ‘Gradient operator>=(const Gradient&, double)’ with ‘C++’ linkage
autodif.c:1664: error: conflicts with new declaration with ‘C’ linkage
autodif.h:77: error: previous declaration of ‘Gradient operator>=(const Gradient&, int)’ with ‘C++’ linkage
autodif.c:1673: error: conflicts with new declaration with ‘C’ linkage
autodif.h:78: error: previous declaration of ‘Gradient operator>=(double, const Gradient&)’ with ‘C++’ linkage
autodif.c:1678: error: conflicts with new declaration with ‘C’ linkage
autodif.h:79: error: previous declaration of ‘Gradient operator>=(int, const Gradient&)’ with ‘C++’ linkage
autodif.c:1687: error: conflicts with new declaration with ‘C’ linkage
autodif.h:81: error: previous declaration of ‘Gradient operator<(const Gradient&, const Gradient&)’ with ‘C++’ linkage
autodif.c:1692: error: conflicts with new declaration with ‘C’ linkage
autodif.h:82: error: previous declaration of ‘Gradient operator<(const Gradient&, double)’ with ‘C++’ linkage
autodif.c:1699: error: conflicts with new declaration with ‘C’ linkage
autodif.h:83: error: previous declaration of ‘Gradient operator<(const Gradient&, int)’ with ‘C++’ linkage
autodif.c:1708: error: conflicts with new declaration with ‘C’ linkage
autodif.h:84: error: previous declaration of ‘Gradient operator<(double, const Gradient&)’ with ‘C++’ linkage
autodif.c:1713: error: conflicts with new declaration with ‘C’ linkage
autodif.h:85: error: previous declaration of ‘Gradient operator<(int, const Gradient&)’ with ‘C++’ linkage
autodif.c:1722: error: conflicts with new declaration with ‘C’ linkage
autodif.h:87: error: previous declaration of ‘Gradient operator<=(const Gradient&, const Gradient&)’ with ‘C++’ linkage
autodif.c:1728: error: conflicts with new declaration with ‘C’ linkage
autodif.h:88: error: previous declaration of ‘Gradient operator<=(const Gradient&, double)’ with ‘C++’ linkage
autodif.c:1735: error: conflicts with new declaration with ‘C’ linkage
autodif.h:89: error: previous declaration of ‘Gradient operator<=(const Gradient&, int)’ with ‘C++’ linkage
autodif.c:1744: error: conflicts with new declaration with ‘C’ linkage
autodif.h:90: error: previous declaration of ‘Gradient operator<=(double, const Gradient&)’ with ‘C++’ linkage
autodif.c:1749: error: conflicts with new declaration with ‘C’ linkage
autodif.h:91: error: previous declaration of ‘Gradient operator<=(int, const Gradient&)’ with ‘C++’ linkage
autodif.c:1758: error: conflicts with new declaration with ‘C’ linkage
autodif.h:93: error: previous declaration of ‘Gradient operator==(const Gradient&, const Gradient&)’ with ‘C++’ linkage
autodif.c:1764: error: conflicts with new declaration with ‘C’ linkage
autodif.h:94: error: previous declaration of ‘Gradient operator==(const Gradient&, double)’ with ‘C++’ linkage
autodif.c:1771: error: conflicts with new declaration with ‘C’ linkage
autodif.h:95: error: previous declaration of ‘Gradient operator==(const Gradient&, int)’ with ‘C++’ linkage
autodif.c:1780: error: conflicts with new declaration with ‘C’ linkage
autodif.h:96: error: previous declaration of ‘Gradient operator==(double, const Gradient&)’ with ‘C++’ linkage
autodif.c:1785: error: conflicts with new declaration with ‘C’ linkage
autodif.h:97: error: previous declaration of ‘Gradient operator==(int, const Gradient&)’ with ‘C++’ linkage
autodif.c:1794: error: conflicts with new declaration with ‘C’ linkage
autodif.h:99: error: previous declaration of ‘Gradient operator!=(const Gradient&, const Gradient&)’ with ‘C++’ linkage
autodif.c:1800: error: conflicts with new declaration with ‘C’ linkage
autodif.h:100: error: previous declaration of ‘Gradient operator!=(const Gradient&, double)’ with ‘C++’ linkage
autodif.c:1807: error: conflicts with new declaration with ‘C’ linkage
autodif.h:101: error: previous declaration of ‘Gradient operator!=(const Gradient&, int)’ with ‘C++’ linkage
autodif.c:1816: error: conflicts with new declaration with ‘C’ linkage
autodif.h:102: error: previous declaration of ‘Gradient operator!=(double, const Gradient&)’ with ‘C++’ linkage
autodif.c:1821: error: conflicts with new declaration with ‘C’ linkage
autodif.h:103: error: previous declaration of ‘Gradient operator!=(int, const Gradient&)’ with ‘C++’ linkage
autodif.c:1830: error: conflicts with new declaration with ‘C’ linkage
autodif.h:105: error: previous declaration of ‘Gradient operator!(const Gradient&)’ with ‘C++’ linkage
autodif.c:1837: error: conflicts with new declaration with ‘C’ linkage
autodif.h:106: error: previous declaration of ‘Gradient operator&&(const Gradient&, const Gradient&)’ with ‘C++’ linkage
autodif.c:1850: error: conflicts with new declaration with ‘C’ linkage
autodif.h:107: error: previous declaration of ‘Gradient operator||(const Gradient&, const Gradient&)’ with ‘C++’ linkage
autodif.c:1860: error: conflicts with new declaration with ‘C’ linkage
autodif.h:125: error: previous declaration of ‘char* GetExpr_(const Gradient&)’ with ‘C++’ linkage
autodif.c:1869: error: conflicts with new declaration with ‘C’ linkage
autodif.c: In function ‘char* GetExpr_(const Gradient&)’:
autodif.c:1872: error: invalid conversion from ‘const char*’ to ‘char*’
autodif.h: In function ‘Gradient operator/(int, const Gradient&)’:
autodif.h:126: error: previous declaration of ‘char* GetExprT_(const Gradient&)’ with ‘C++’ linkage
autodif.c:1875: error: conflicts with new declaration with ‘C’ linkage
autodif.h:128: error: previous declaration of ‘char* GetDer1_(const Gradient&, int)’ with ‘C++’ linkage
autodif.c:1885: error: conflicts with new declaration with ‘C’ linkage
autodif.c: In function ‘char* GetDer1_(const Gradient&, int)’:
autodif.c:1888: error: invalid conversion from ‘const char*’ to ‘char*’
autodif.h: In function ‘Gradient operator/(int, const Gradient&)’:
autodif.h:129: error: previous declaration of ‘char* GetDer1T_(const Gradient&, int)’ with ‘C++’ linkage
autodif.c:1891: error: conflicts with new declaration with ‘C’ linkage
autodif.h:131: error: previous declaration of ‘char* GetDer2_(const Gradient&, int, int)’ with ‘C++’ linkage
autodif.c:1901: error: conflicts with new declaration with ‘C’ linkage
autodif.c: In function ‘char* GetDer2_(const Gradient&, int, int)’:
autodif.c:1904: error: invalid conversion from ‘const char*’ to ‘char*’
autodif.h: In function ‘Gradient operator/(int, const Gradient&)’:
autodif.h:132: error: previous declaration of ‘char* GetDer2T_(const Gradient&, int, int)’ with ‘C++’ linkage
autodif.c:1907: error: conflicts with new declaration with ‘C’ linkage
autodif.h:134: error: previous declaration of ‘char* GetDer3_(const Gradient&, int, int, int)’ with ‘C++’ linkage
autodif.c:1918: error: conflicts with new declaration with ‘C’ linkage
autodif.c: In function ‘char* GetDer3_(const Gradient&, int, int, int)’:
autodif.c:1921: error: invalid conversion from ‘const char*’ to ‘char*’
autodif.h: In function ‘char* GetDer3T_(const Gradient&, int, int, int)’:
autodif.h:135: error: previous declaration of ‘char* GetDer3T_(const Gradient&, int, int, int)’ with ‘C++’ linkage
autodif.c:1924: error: conflicts with new declaration with ‘C’ linkage

autodif.cc

// UNIX specific part


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
///#include <math.h>
#include <ctype.h>


#define Malloc    malloc
#define Free    free
#define Memset    memset
#define MemCopy    memcpy
#define StrCpy    strcpy
#define StrCat    strcat
#define StrCmp    strcmp
#define StrNCmp    strncmp
#define StrChr    strchr
#define StrLen    strlen
#define StrPbkr strpbrk

#define MemFree(p) if (p) Free(p)
#define StringSave(p) (p ? _StringSave(p) : NULL)
#define StrSave(p) _StringSave(p)
#define StringLen(p) (p ? StrLen(p) : 0)

#include "autodif.h"

/* Must be the same as in programs generated by contdiff.c */
extern FILE *MStream_;
extern FILE *FStream_;

static void *MemNew(int size) {
  void *p;
  p=Malloc(size);
  if (!p) {
    fprintf(MStream_,"\n\n\n#error ===>Cannot MemNew(%i)\n\n\n",size);
    fclose(MStream_);
    abort();
  }
  return Memset(p,0,size);
}

static void *MemNewN(int size) {
  void *p;
  p=Malloc(size);
  if (!p) {
    fprintf(MStream_,"\n\n\n#error ===>Cannot MemNew(%i)\n\n\n",size);
    fclose(MStream_);
    abort();
  }
  return p;
}


#define _StringSave(p) strdup(p)

#define near

#include "autodif.c"

autodif.h

// Enable the External Differentiator
#define ED    1    // MUST be the same as in common.h

typedef enum {DEF,INDEP,TEMP,GRAD} VarKind;    // Kind of variable

class Gradient {
  char **Expr;        // expression(s)
  char ***Der1;        // and gradient(s)
  char ***Der2;        // and second order derivatives
  char ***Der3;        // and third order derivatives
  int n2,n3;        // numbers of 2-d and 3-d order derivatives
  int Vardim;
  int Index;
  VarKind Kind;            // independent, temporary, or result var
  Gradient *Parent;
 public:
  Gradient(char *name=NULL, int varno=0, int vardim=1, VarKind kind=DEF);
  Gradient(double c);
  Gradient(int i);
  Gradient(const Gradient &g);    // copy
  ~Gradient();
  Gradient operator[](int index) {
    Gradient t=*this;
    t.Index=index;
    return t;
  };

  Gradient &operator=(const Gradient &f);
  Gradient &operator=(double c);
  Gradient &operator=(int i);
  Gradient &operator+=(const Gradient &f);
  Gradient &operator+=(double c);
  Gradient &operator+=(int i);
  Gradient &operator-=(const Gradient &f);
  Gradient &operator-=(double c);
  Gradient &operator-=(int i);
  Gradient &operator*=(const Gradient &f);
  Gradient &operator*=(double c);
  Gradient &operator*=(int i);
  Gradient &operator/=(const Gradient &f);
  Gradient &operator/=(double c);
  Gradient &operator/=(int i);

  friend Gradient operator+(const Gradient &f, const Gradient &g);
  friend Gradient operator+(const Gradient &f, double c);
  friend Gradient operator+(double c, const Gradient &g);
  friend Gradient operator+(const Gradient &f, int i);
  friend Gradient operator+(int i, const Gradient &g);

  friend Gradient operator*(const Gradient &f, const Gradient &g);
  friend Gradient operator*(const Gradient &f, double c);
  friend Gradient operator*(double c, const Gradient &g);
  friend Gradient operator*(const Gradient &f, int i);
  friend Gradient operator*(int i, const Gradient &g);

  friend Gradient operator-(const Gradient &f, const Gradient &g);
  friend Gradient operator-(const Gradient &f);
  friend Gradient operator-(const Gradient &f, double c);
  friend Gradient operator-(double c, const Gradient &g);
  friend Gradient operator-(const Gradient &f, int i);
  friend Gradient operator-(int i, const Gradient &g);

  friend Gradient operator/(const Gradient &f, const Gradient &g);
  friend Gradient operator/(const Gradient &f, double c);
  friend Gradient operator/(double c, const Gradient &g);
  friend Gradient operator/(const Gradient &f, int i);
  friend Gradient operator/(int i, const Gradient &g);

  friend Gradient operator>(const Gradient &f, const Gradient &g);
  friend Gradient operator>(const Gradient &f, double c);
  friend Gradient operator>(const Gradient &f, int i);
  friend Gradient operator>(double c, const Gradient &f);
  friend Gradient operator>(int i, const Gradient &f);

  friend Gradient operator>=(const Gradient &f, const Gradient &g);
  friend Gradient operator>=(const Gradient &f, double c);
  friend Gradient operator>=(const Gradient &f, int i);
  friend Gradient operator>=(double c, const Gradient &f);
  friend Gradient operator>=(int i, const Gradient &f);

  friend Gradient operator<(const Gradient &f, const Gradient &g);
  friend Gradient operator<(const Gradient &f, double c);
  friend Gradient operator<(const Gradient &f, int i);
  friend Gradient operator<(double c, const Gradient &f);
  friend Gradient operator<(int i, const Gradient &f);

  friend Gradient operator<=(const Gradient &f, const Gradient &g);
  friend Gradient operator<=(const Gradient &f, double c);
  friend Gradient operator<=(const Gradient &f, int i);
  friend Gradient operator<=(double c, const Gradient &f);
  friend Gradient operator<=(int i, const Gradient &f);

  friend Gradient operator==(const Gradient &f, const Gradient &g);
  friend Gradient operator==(const Gradient &f, double c);
  friend Gradient operator==(const Gradient &f, int i);
  friend Gradient operator==(double c, const Gradient &f);
  friend Gradient operator==(int i, const Gradient &f);

  friend Gradient operator!=(const Gradient &f, const Gradient &g);
  friend Gradient operator!=(const Gradient &f, double c);
  friend Gradient operator!=(const Gradient &f, int i);
  friend Gradient operator!=(double c, const Gradient &f);
  friend Gradient operator!=(int i, const Gradient &f);

  friend Gradient operator!(const Gradient &f);
  friend Gradient operator&&(const Gradient &f, const Gradient &g);
  friend Gradient operator||(const Gradient &f, const Gradient &g);

  friend Gradient fabs(const Gradient &f);
  friend Gradient exp(const Gradient &f);
  friend Gradient log(const Gradient &f);
  friend Gradient sqrt(const Gradient &f);
  friend Gradient pow(const Gradient &f, double p);
  friend Gradient pow(const Gradient &f, int i);
  friend Gradient pow(const Gradient &f, const Gradient &g);
  friend Gradient sin(const Gradient &f);
  friend Gradient cos(const Gradient &f);
  friend Gradient tan(const Gradient &f);
  friend Gradient asin(const Gradient &f);
  friend Gradient acos(const Gradient &f);
  friend Gradient atan(const Gradient &f);
  friend Gradient iff(const Gradient &c, const Gradient &f, const Gradient &g);

// This file actually is few thousand lines.

Note that the .c and the .cc have classes, so should be C++, right?

right. and audiodiff.cc #includes audiodiff.c
i can't think of solutions other than changing the source (making it const correct) unless you want to use a very old version of g++.

you could also suppress the specific error in your original compile
error: invalid conversion from ‘const char*’ to ‘char*’
(convert it to a mere warning) by using the -fpermissive switch
eg. g++ -fpermissive myfile.cc

the code would then compile in the original form; i would not feel very comfortable about doing this though.

i can't think of solutions other than changing the source (making it const correct) unless you want to use a very old version of g++.

you could also suppress the specific error in your original compile
error: invalid conversion from ‘const char*’ to ‘char*’
(convert it to a mere warning) by using the -fpermissive switch
eg. g++ -fpermissive myfile.cc

the code would then compile in the original form; i would not feel very comfortable about doing this though.

That helps a lot, thanks. The code is pretty old, so it makes sense that an older version of g++ would compile it.

Why would you be uncomfortable with the -fpermissive?

How do I change the source code to make the const correct?

Why would you be uncomfortable with the -fpermissive?

because it could pass a serious error as valid code with nasty surprises at runtime. for example,

void foo( const char* cstr )
{
  cstr[0] = 'a' ; // will only give a warning with -fpermissive, 
  // but would cause  disater at runtime
} 

int main()
{
  static const char hello[] = "hello world" ;
  foo( hello  ) ;
  // if function foo is defined in a different translation unit, 
  // the optimizer could eliminate the following as dead code
  // even if foo did work!
  if( hello[0] == 'a' )
  {
    // whatever
  }
}

How do I change the source code to make the const correct?

you need to look at the places where the error was occurring. and make appropriate modifications. eg. if a function wants to modify a string parameter, it should declare it as a char*, not a const char*. and at the place where you are calling the function, you have to ensure that you have a modifiable array of chars.

g++ prior to 3.0 was not a C++ compiler at all (just as turbo C++ is not C++). Non-conforming (incorrect) code that compiled with these versions of g++ would be correctly rejected by later versions. g++ 3.0 was the first version which had a C++ standard library; version 3.4.0 included a complete rewrite of the parser. ISO C++ conformance is pretty good in versions 3.4.0 or above.
the -fpermissive switch was given as a hack to compile legacy non-conforming code (alas, a lot of open source code still uses this switch). if you are not writing throw-away code, it would be a good idea to clean up the mess before you start building more functionality in. and compile with the
std=c++98 (or std=c++0x in g++ 4.2.0 or above) switch.

Thanks for your help, Vijayan. Compiling with the -fpermissive gave me many new errors... It seems that every solution uncovers more errors. :( For now I'll just use a precompiled version which I got to work.

Thanks again!

...Compiling with the -fpermissive gave me many new errors...

it would not; -fpermissive merely converts some errors into warnings. compile with -fpermissive exactly as you dsescribed in your original post (not with the extern "C" etc.).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.