This is the mail archive of the gcc-bugs@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]

[Bug c/30622] char *p; p = "str"; puts "str" into rodata



------- 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


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