K17
K17

Reputation: 697

Conversion from string literal to char *

I am trying to make a c function work in some publicly available linear algebra code.

the publicly available prototype is…

int ilaenv_(int *, char *, char *, int *, int *,int *, int *);

The publicly available code has the function call…

nb = ilaenv_(&c__1, "DGEQRF", " ", m, n, &c_n1, &c_n1); 

where m, n, c_1, and c_n1 are integers,

The error message is.

C++ 11 does not allow conversation from string literal to char *.

I did not create the code, but downloaded it from the LAPACK site. I hesitate to make too many changes to publicly available code that supposedly works, for fear of introducing errors. However, this error is showing up on a number of functions in the program that I am working on.

How can I resolve this?

Upvotes: 3

Views: 9279

Answers (3)

Albertus
Albertus

Reputation: 66

Sorry for being so late, I just bumped into this problem. You can try this,

string dgeqrf = "DGEQRF";

One problem with using "const char *" is code like this,

string formatString;
switch (format)
{
    case FORMAT_RGB:  formatString = "RGB"; break;
    case FORMAT_RGBA: formatString = "RGBA"; break;
    case FORMAT_TP10: formatString = "TP10"; break;
    default:          formatString = "Unsupported"; break;
}

If you declare formatString as a "const char *", this won't work.

Upvotes: 1

senfen
senfen

Reputation: 907

Your function takes "char *", not "const char *". String literals can be assigned only to "const char *".

Upvotes: 8

Arkku
Arkku

Reputation: 42149

To be safe, you could create char arrays initialised to the same values, for example:

char dgeqrf[] = "DGEQRF";
char space[] = " ";

Or you could check the source code of the function; if it doesn't actually modify the contents of those arrays you could change the arguments to const char *.

Upvotes: 6

Related Questions