g++ warning: deprecated conversion from string constant to 'char*'
Hi guys,
My problem is that the warning keeps apperaing when I run g++ compilation. Say, I have a system runtime function with header (imaginary)sysruntime.h: void printfunction(char *line); Then in my .cpp file, I will include the above header #include <sysruntime.h> Then, I do the below: Line12: char *linetoprint = "Print this line"; Line13: printfunction(linetoprint); But, I will get the warning message "Line12: deprecated conversion from string constant to 'char*'". (Even though it compiles) My question is how should I declare my char* so that I wont get this warning message, and can still run printfunction(char* line) correctly? Thks in advance! Chinho |
Try:
Code:
const char *linetoprint = "Print this line"; |
Also fix your function to be:
Code:
void printfunction(const char *line); |
Hi guys,
In my real situation, the function i described here is actually part of a system runtime library, so I cant change the function as you adviced. So I think, the adviced below dont work too: Code:
const char *linetoprint = "Print this line"; Warmest Regards, Chinho |
d.cpp:
Code:
#include <stdio.h> Code:
anisha@linux-uitj:~> g++ d.cpp -Ld.h -Wall -Wextra |
Code:
const char* linetoprint = "Print this line"; |
Hi anisha, thanks a gazillion!
Hi whitney, none. I was only stating an example :) |
Quote:
|
All times are GMT -5. The time now is 03:37 PM. |