F
Flash Gordon
The above assignment loses the const qualifier.
No it doesn't. One of the quirks of the C language is that it is *not*
const qualified. Modifying string literals is undefined behaviour
(forbidden) because the standard explicitly states that it is and for no
other reason.
> In case you
are using gcc, -Wwrite-strings will emit warnings. Use arrays if
you want to modify content.
This is correct.
#include <stdio.h>
int main (void)
{
char *string = "testing";
printf("%s\n", string);
return 0;
}
There is nothing wrong with the above code. The standard does not
require a diagnostic and it does not invoke undefined behaviour.
gcc: aliased to gcc -Wall -W -ansi -pedantic
str.c: In function `main':
str.c:4: warning: initialization discards qualifiers from pointer
target type
I agree that the warning is useful. Just not required by the standard
and not provided by all compilers.