From owner-freebsd-bugs Sat Mar 31 5:50:11 2001 Delivered-To: freebsd-bugs@freebsd.org Received: from smtp8.xs4all.nl (smtp8.xs4all.nl [194.109.127.134]) by hub.freebsd.org (Postfix) with ESMTP id 843D937B719 for ; Sat, 31 Mar 2001 05:50:08 -0800 (PST) (envelope-from dim@xs4all.nl) Received: from dim0 (0.xs4all.nl [213.84.53.200]) by smtp8.xs4all.nl (8.9.3/8.9.3) with ESMTP id PAA23332; Sat, 31 Mar 2001 15:49:43 +0200 (CEST) Message-ID: <200103311549350784.00F17646@smtp.xs4all.nl> In-Reply-To: References: X-Mailer: Calypso Version 3.20.02.00 (4) Date: Sat, 31 Mar 2001 15:49:35 +0200 From: "Dimitry Andric" To: "Vladimir Mandro" Cc: freebsd-bugs@FreeBSD.ORG Subject: Re: bug in gcc or my hands? Content-Type: text/plain; charset="us-ascii" Sender: owner-freebsd-bugs@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.org -----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 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