error: invalid conversion from ‘const char*’ to ‘char*’

Compiling xpp (The X Printing Panel) on SL6 (RHEL6 essentially):

xpp.cxx: In constructor �printFiles::printFiles(int, char**, int&)�:
xpp.cxx:200: error: invalid conversion from �const char*� to �char*�

The same error with all c++ constructors - gcc 4.4.4.

If anyone can throw any light on this it would be very much appreciated - I'm after getting BitBox[1] up and running and it won't run without xpp.
[1] Free 'Browser in a Box' Runs Firefox 4 with Ultra Security | PCWorld Business Center

Casting the expression on the right side of the equals sign should take care of this.

Keep in mind that the code might still have to abide by the const-ness even after you typecast it. Typecasting a "string" to char * won't stop the program from crashing when you try to modify it.

Not if it's cast from char* to const char* but the other way around...sure!

The function prototype:

printFiles::printFiles(int  argc,         /* I - Number of command-line arguments */
                          char *argv[],      /* I - Command-line arguments */
                          int &exitstat);    /* O - != 0 if an error occurred */

I was working on the basis it was probably something to do with the version of gcc in use - however compat libs and gcc3 do not seem to fix it.

xpp.cxx:200: error: invalid conversion from �const char*� to �char*�

Like shamrock says you may need to modify something to fix it. Since you haven't posted line 200 (and a bit of context) we don't know exactly what's making it throw up though.

OK, I was thinking the error was in the function prototype, after all that was what was given, however it is further down (rusty!):

              {
              char *tmp; 

              if ((tmp = strchr(dest,'/'))) {
                tmp[0] = '\0';
                instance = tmp + 1;
              }

Specifically the tmp assignment.

The phenomena is explained here by the looks... GCC 4.4 Release Series � Porting to the New Tools

tmp=(char *)strchr(...

1 Like
if ((tmp = (char*)strchr(dest,'/'))) {

Seems to have fixed it!

Thanks for your time guys :slight_smile: