Originally Posted by
root4
If you add 'const', before, you get no warning from -Wwrite-strings, as expected (you get one if there is no const). With -Wall, what warning do you get?
With -Wall, I get this:
Code:
seg.c: In function ‘main’:
seg.c:6: warning: writing into constant object (argument 2)
and the code looks like this:
Code:
#include <stdio.h>
int main(void)
{
const char *p="Hello";
scanf("%s",p);
printf("%s",p);
return 0;
}
I removed the const part of the declaration, and got this:
Code:
kermit@fastbox ~/cprogs/board $ gcc -Wwrite-strings -o seg seg.c
seg.c: In function ‘main’:
seg.c:5: warning: initialization discards qualifiers from pointer target type
However, when I use -Wall with the const removed, I get no warning at all..