egcs bug? (fwd)

Alexandre Oliva oliva@dcc.unicamp.br
Sat Dec 19 19:19:00 GMT 1998


On Dec 19, 1998, Paul Ezust <ezust@zeus.cas.suffolk.edu> wrote:

> #include <iostream.h>

> int main() { char * const b = "abcdef"; b[3] = '3';
>   cout << b << endl; }

> strange.cc:5: Internal compiler error.
> gcc version egcs-2.90.27 980315 (egcs-1.0.2 release)

> gcc version egcs-2.91.60 19981201 (egcs-1.1.1 release)
> zeus:/usr/clas1/staff/ezust/C++> g++ strange.cc
> zeus:/usr/clas1/staff/ezust/C++> a.out
> Segmentation fault

You can't modify a constant string, even though there exists a
deprecated conversion of literal strings (that have type `const char
[N]') to `char*'.  `b' points into a read-only segment, so you can't
modify its contents, that's why the program crashes.  Unless you
compile with -fwritable-strings, but then you're kind of cheating,
since the Standard doesn't allow literal strings to be modified...

-- 
Alexandre Oliva  http://www.dcc.unicamp.br/~oliva  aoliva@{acm.org}
oliva@{dcc.unicamp.br,gnu.org,egcs.cygnus.com,samba.org}
Universidade Estadual de Campinas, SP, Brasil




More information about the Gcc-bugs mailing list