C compilers are not required to detect the first error, because C string literals are not const.
N1256 C99:
6.4.5 5:
7 , . , . char ; [...]
6:
, , . , undefined.
(C11 .)
, "hello, world" char[13] (not const char[13]), char* .
const undefined, , , (, ). undefined, , const ( ); , , undefined.
, :
#include <stdio.h>
void print_string(char *s) {
printf("%s\n", s);
}
int main(void) {
print_string("Hello, world");
return 0;
}
const, "hello, world" , ( const) char*, . , undefined, print_string() , s.
. pre-ANSI C const, , char* promises, , . const ANSI C (1989) , .
gcc -Wwrite-strings , const, gcc , :
const char (*p)[6] = &"hello";
("hello" char[6], &"hello" char (*)[6], p. -Wwrite-strings, &"hello" type const char (*)[6].) , -Wall, -Wextra -Wwrite-strings.
, , -Wwrite-strings, , . C-, , -Wwrite-strings.
( , ++ const, , Bjarne Stroustrup ++, C.)