Both GCC and Clang do not complain if I assign a string literal to a char*
, even when using lots of pedantic options (-Wall -W -pedantic -std=c99
):
char *foo = "bar";
while they (of course) do complain if I assign a const char*
to a char*
.
Does this mean that string literals are considered to be of char*
type? Shouldn't they be const char*
? It's not defined behavior if they get modified!
And (an uncorrelated question) what about command line parameters (ie: argv
): is it considered to be an array of string literals?
Question&Answers:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…