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: Difference between these pointer syntaxes Date: Thu, 18 Aug 2016 10:34:48 -0700 Organization: None to speak of Lines: 23 Message-ID: References: <4991b886-1f54-4098-bf57-ba59710b99d1@googlegroups.com> <87bn0rut34.fsf@bsb.me.uk> <9283b112-8250-4e0b-b149-6ca728a3200b@googlegroups.com> <07faa95e-2470-4375-93e9-15e79ee4e0e4@googlegroups.com> <55578778-4482-458e-b43d-b763732c0054@googlegroups.com> <87mvkas5gb.fsf@bsb.me.uk> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx02.eternal-september.org; posting-host="945944de09706c9b4e29b53c9d2efdc2"; logging-data="19903"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19NgRXfLoZtjk0AqMpV0Hai" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:mmtqX53tjqRGWPZ6wPAsF+pQpD4= sha1:7RufAY+99rGHAgnCoQYHTF4HdK0= Xref: csiph.com comp.lang.c:92466 David Brown writes: [...] > That is a challenge for const correctness. C takes the attitude that it > can't be done nicely in C (you'd need two versions of the strchr > function, and it would be up to the user to pick the right one) - so it > gives you a single version that takes a "const char *" and returns a > "char *". This function can't be written by the user in a fully > portable manner, because it contains undefined behaviour - but it's fine > for the standard library because that can use whatever > implementation-defined behaviour is needed to make it safe. It is then > up to the user to keep it safe - there is no compile-time checking. [...] In my opinion, the ANSI C committee made a mistake here. It *could* have been done nicely in C -- by having introducing two different versions of the strchr function (perhaps strchr and strcchr). Several other standard library functions have the same problem. -- 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"