Hi,
Rob said:
Recent gccs
uniquify strings and put them in .text. If you pass -fwriteable-strings to gcc, the former version will >work.
Indeed it worked when passing -fwriteable-strings;
I had checked on 2 machines , one with gcc 2.9.6 (RH7.3) and one with gcc 3.3.3 , which is
quite new, on Fedora Core 2; and in both you must add the -fwriteable-strings so it won't crash ;
telford noted that info gcc shows that this option is deprecated. http://lists.slug.org.au/archives/slug/2005/04/msg00404.html
It could be that in newer versions (gcc 3.4,gcc4) this flag is built-in , I don't know; but in man gcc in gcc 3.3.3 they also say
that this is a bad idea ;I must find time to check what implications such a flag have and if
it can cause any troubles and in which scenarios.
Regards, Amir
From: Robert Collins <[EMAIL PROTECTED]> To: Amir Binyamini <[EMAIL PROTECTED]> CC: [EMAIL PROTECTED], [email protected] Subject: RE: [SLUG] GCC question Date: Tue, 19 Apr 2005 17:48:13 +1000
On Tue, 2005-04-19 at 09:53 +0300, Amir Binyamini wrote:
> Well , what I said , and I repeating it now , is : > > Take a little program like this: > > int main() > { > char* test = "ab"; > (*test)++; > > printf("finished\n"); > } > > Compiling it with gcc on RefHat Linux an running it gives a segmentation > fault. > > > On the other hand,if instead (*test)++ you'll write > char c = *test; > c++; > > It will not crash.
Ok, this is because the two are not equivalent. the former mutates 'test' in place - which if its in the .text isn't permitted. Recent gccs uniquify strings and put them in .text. If you pass -fwriteable-strings to gcc, the former version will work.
Rob
-- GPG key available at: <http://www.robertcollins.net/keys.txt>. << signature.asc >>
_________________________________________________________________
FREE pop-up blocking with the new MSN Toolbar � get it now! http://toolbar.msn.click-url.com/go/onm00200415ave/direct/01/
-- SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/ Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html
