Path: csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: writing a c program to substitute text Date: Sun, 26 Feb 2017 17:44:23 -0800 Organization: None to speak of Lines: 39 Message-ID: References: <2c574151-71a0-4bcf-a904-50a13eaf81b0@googlegroups.com> <182b9ecd-0719-4704-9118-b5a24cb022e9@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx02.eternal-september.org; posting-host="704c5d663da9e0150365451e4cbc43e2"; logging-data="30939"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+A8ThaN3WiV8OfjPdB3Hok" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:JmgjOuwmbLiDFgakiEh24Ca80CM= sha1:Lk18qQzWlvkRMSOl3bFFRFNRSnk= Xref: csiph.com comp.lang.c:104811 Malcolm McLean writes: > On Sunday, February 26, 2017 at 11:53:30 PM UTC, David Brown wrote: >> On 26/02/17 23:53, Malcolm McLean wrote: >> > Generally people think that C is unsafe because they are used to >> > languages where strings are higher-level objects. >> >> That's one possibility. Most people thing "C is unsafe" because they >> don't know much about it, or how to write safe code - and they know that >> some people write unsafe C code. >> >> > And in C terms >> > that means, "guaranteed to be on the heap". >> >> That is complete nonsense. Putting something on the heap is never safer >> in any way than having it local to a function or statically allocated. >> And in particular, the safest strings are those that are constants that >> are fixed in the program - string literals. >> > No, the only way to make objects safe is to have a rigorously controlled > memory model for them. Which means some form of managed pointer with > the object on the heap. (I know that as a micro- optimisation C++ > std::strings are actually stack objects for short strings, I'm talking > generally and loosely). More nonsense. How is "a rigorously controlled memory model" involving "some form of managed pointer with the object on the heap" safer than a simple string literal (which designates an object that exists for the entire execution of the program)? We don't know whether a string literal satisfies the OP's requirements; we'll have to wait for clarification on what those requirements are. [...] -- Keith Thompson (The_Other_Keith) kst-u@mib.org Working, but not speaking, for JetHead Development, Inc. "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister"