This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/30622] char *p; p = "str"; puts "str" into rodata
- From: "pinskia at gcc dot gnu dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 28 Jan 2007 17:31:46 -0000
- Subject: [Bug c/30622] char *p; p = "str"; puts "str" into rodata
- References: <bug-30622-12956@http.gcc.gnu.org/bugzilla/>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- Comment #4 from pinskia at gcc dot gnu dot org 2007-01-28 17:31 -------
(In reply to comment #3)
> Sorry! Bug in the testcase, should be "char *p".
> I remember that string literals are special - they decay to "const char *" OR
> to "char*" depending on context. In this context, it should decay to "char*",
> and it does - gcc doesn't complain "assingment of const to non-const", the bug
> is that gcc placed "str" in ro section.
They are still considered constant even though the type decays to char*. The
reason why the type of a string literal decays to char* is because before
C90/C89, const did not exist so the C standards committee wantted to support
older code.
Anyways if you want a warning use -Wwrite-strings.
--
pinskia at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution| |INVALID
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30622