3

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?

Iharob Al Asimi
  • 52,653
  • 6
  • 59
  • 97
K17
  • 697
  • 3
  • 8
  • 26
  • You can just cast constness but I don't know if that can be good. – Iharob Al Asimi Mar 04 '15 at 17:56
  • 3
    Does it really say `conversation`? Please use the actual error strings. And fix the title. – Eugene Sh. Mar 04 '15 at 17:57
  • Not a strict duplicate, but this should have some helpful information: http://stackoverflow.com/questions/1704407/what-is-the-difference-between-char-s-and-char-s-in-c/1704433#1704433 – Adam Mar 04 '15 at 17:57
  • Yes please post the exact error message, copy and paste, it's not possible that it says `conversation`. – Iharob Al Asimi Mar 04 '15 at 17:58
  • I guess you can't talk about string literals and char* in c++11. Freaken passive-aggressive language... – thang Mar 04 '15 at 18:00
  • is parameter 3 space? – Masoud AMR Mar 04 '15 at 18:00
  • Oops. one of those "spell checkers" got me again. "conversation" should be conversion. So the exact message is .... "C++ 11 does not allow conversion from string literal to char * – K17 Mar 05 '15 at 02:31

3 Answers3

8

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

senfen
  • 877
  • 5
  • 21
6

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 *.

Arkku
  • 41,011
  • 10
  • 62
  • 84
1

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.

Albertus
  • 56
  • 4
  • re. "if you declare `formatString` as a `const char *` this won't work" – the code shown here will work just fine with `const char *`, but the potential problem is that the function takes `char *` not `const char *` so we don't know if it is going to modify the contents of the string, and modifying the string literals is not permitted. Hence the need to have a modifiable array, either by conversion from `string` or as a `char` array instead of pointer (as per my answer). _Unless_ you need to assign the contents dynamically (like in this answer), the array is simpler. – Arkku Nov 15 '17 at 09:14