Causes
Initializing a character pointer variable with a string literal
In standard C, string literals have type char *
, even though they cannot be modified without invoking undefined behavior (risking a program crash or data corruption). g++
issues a warning to let you know that you are relying on this behavior.
char *x = "foo bar";
Solution 1: Change the "char *" to "const char *"
Most programmers assign all string literals to a pointer of type const char *
, which ensures that they cannot be accidentally written to.
const char *x = "foo bar";
Solution 2: Use a string object instead of a character pointer
string x = "foo bar";
Solution 3: Cast the string literal to type "char *"
char *x = (char *)"foo bar";
'Programming' 카테고리의 다른 글
node.js는 무엇인가? #2 : Hello World 실행하기 (0) | 2013.03.01 |
---|---|
이클립스 Node.js 연동하기 (Eclipse Node.js) (0) | 2013.03.01 |
How to change a remote repository URI using Git? (0) | 2013.02.28 |
(Book) Let Over Lambda—50 Years of Lisp by Doug Hoyte (0) | 2013.02.27 |
Makefile tutorial (0) | 2013.02.26 |