M
Marcin Kalicinski
Why string literals are regarded as char * not as const char *?
(1) void f(char *);
(2) void f(const char *);
f("foo") will call version (1) of function f.
I understand that the exact type of literal "foo" is char[4], which by means
of standard conversion becomes char *. Still, there's something going wrong
here, because this allows modification of "foo", which in my opinion should
be forbidden (because it causes undefined behavior).
Best regards,
Marcin
(1) void f(char *);
(2) void f(const char *);
f("foo") will call version (1) of function f.
I understand that the exact type of literal "foo" is char[4], which by means
of standard conversion becomes char *. Still, there's something going wrong
here, because this allows modification of "foo", which in my opinion should
be forbidden (because it causes undefined behavior).
Best regards,
Marcin