Date: Sat, 31 Mar 2001 15:49:35 +0200 From: "Dimitry Andric" <dim@xs4all.nl> To: "Vladimir Mandro" <vlaman@smela.ldc.net> Cc: freebsd-bugs@FreeBSD.ORG Subject: Re: bug in gcc or my hands? Message-ID: <200103311549350784.00F17646@smtp.xs4all.nl> In-Reply-To: <E14jLOP-0000yy-00@vlaman.smela.ldc.net> References: <E14jLOP-0000yy-00@vlaman.smela.ldc.net>
next in thread | previous in thread | raw e-mail | index | archive | help
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On 2001-03-31 at 16:26 Vladimir Mandro wrote: >I discovered some strange gcc actions. No, you didn't. In your first program, the "Hello" string is a literal, and it is stored by the compiler in READ-ONLY memory. The char pointer s is just pointing at it. The official type of a literal string is "const char *", NOT "char *", at least since a few years. If you want the "old" behaviour, try compiling your program with the "-fwritable-strings" option added to the compiler options. This is not good, however! Think of what happens when such a literal string is modified by one part of the program, and then another part of the program wants to use it. I'm not even talking about multi-threaded programs, but then it would be even more horrible... :) In your second version, you explicitly declare a WRITABLE (ie. non-const) char array named s, with a specified contents. This is NOT a pointer, and you can modify this array as much as you like, of course. This second way is how you should do stuff like this. :) Cheers, - -- Dimitry Andric <dim@xs4all.nl> PGP key: http://www.xs4all.nl/~dim/dim.asc KeyID: 4096/1024-0x2E2096A3 Fingerprint: 7AB4 62D2 CE35 FC6D 4239 4FCD B05E A30A 2E20 96A3 -----BEGIN PGP SIGNATURE----- Version: Encrypted with PGP Plugin for Calypso Comment: http://www.gn.apc.org/duncan/stoa_cover.htm iQA/AwUBOsXSTrBeowouIJajEQLSuACbBbcAkCVZUKvp/2WBP+XqN91Y+K4An0Rv h80pWl80umyuwjz0u4VDWcsS =oVGN -----END PGP SIGNATURE----- To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200103311549350784.00F17646>