Liste des Groupes | Revenir à cl c |
candycanearter07 <candycanearter07@candycanearter07.nomail.afraid>Is there any reason not to always write ...
writes:David Brown <david.brown@hesbynett.no> wrote at 17:56 this Thursday (GMT):[...]No it isn't, nor is it included in -Wall -- and it wouldn't make sensegcc has the option "-Wwrite-strings" that makes string literals in C>
have "const char" array type, and thus give errors when you try to
assign to a non-const char * pointer. But the option has to be
specified explicitly (it is not in -Wall) because it changes the meaning
of the code and can cause compatibility issues with existing correct code.
-Wwrite-strings is included in -Wpedantic.
to do so.
The -Wpedantic option is intended to produce all required diagnostics
for the specified C standard. -Wwrite-strings gives string literals the
type `const char[LENGTH]`, which enables useful diagnostics but is
*non-conforming*.
For example, this program:
```
#include <stdio.h>
int main(void) {
char *s = "hello, world";
puts(s);
}
```
is valid (no diagnostic required), since it doesn't actually write to
the string literal object, but `-Wwrite-strings` causes gcc to warn
about it (because making the pointer non-const creates the potential for
an error).
Les messages affichés proviennent d'usenet.