Operating System - HP-UX
1827295 Members
4039 Online
109717 Solutions
New Discussion

String Literals in r/o memory

 
kenneth kahn_1
New Member

String Literals in r/o memory

I have some code that results in

Warning 829: Implicit conversion of string literal to 'char

I understand what is causing this
and how to 'fix' it (changing the
char * to const char *). I also
know I can just ignore it by using -W829.

I've also tried using the compiler switch +ESnolit,
which says it will place
string literals into standard
memory instead of r/o memory
which is the default (+ESlit).
This doesn't seem to work, using +ESnolit still results
in the 829. Am I interpreting
this switch incorrectly, shouldn't it resolve this
problem?
1 REPLY 1
A. Clay Stephenson
Acclaimed Contributor

Re: String Literals in r/o memory

That compiler flag has little to do with this. It's really saying that you might plan to change the contents of that string. You really should use the (const char *)
casting to tell the compiler that you don't intend to change this string; that makes it possible for the optimizer to replace multiple instances of the string literal with just one instance.

In your specific case, the compiler is asking you to explicitly indicate your intentions for this string.
If it ain't broke, I can fix that.