How Do You Troubleshoot the C Program Error “warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]”?

Problem scenario
You try to compile a program with "gcc".  You get this output:

"warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]"

What do you do to compile your program?

The program may still compile and run.  Look for the a.out file to be created.  It may be a working C program.  Just run it like this:  ./a.out

To get rid of the error, which is recommended as future C compilers may not be so forgiving, do the following.  First find the line number throwing the error.  The compilation error should have looked like this: deprecated...

That means line 15 of the program named is causing the problem.  Line 15 will look something like this:

char* other = "coolphrase";

Rewrite it to be like this:

char const * other = "coolphrase";

Leave a comment

Your email address will not be published. Required fields are marked *