This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Are string literals _always_ allocated in the RO section?


jlh <jlh@gmx.ch> writes:

> Denis Zaitsev wrote:
>> Should it be considered as a bug?
>
> Not a bug, but surely a missed opportunity to issue a warning, which
> 3.4.3 doesn't with -Wall.  "y" is not writable and should therefore
> be of type 'const char *' making the conversion to 'char *' invalid.

The C standard specifically says that the type of a string literal is
'char [N]' (N == strlen() + 1), despite its not being writable
(C99 6.4.5p5).

If you want, you can use the -Wwrite-strings command line option,
which makes them 'const char *' (as they are in C++).  This is not in
-Wall because many large C programs are not written for it, and fixing
all the warnings can be an enormous amount of work.

zw


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]