Path: csiph.com!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: C pointer semantics with dynamically allocated struct Date: Thu, 08 Oct 2015 10:43:42 -0700 Organization: None to speak of Lines: 28 Message-ID: References: <878u7jo9xi.fsf@bsb.me.uk> <1cb437ed-216b-439b-b892-60d5c8decf33@googlegroups.com> <3fc6919f-4b41-4eaf-8c4a-ca00ca97fce3@googlegroups.com> <49f58313-f3f1-41d9-9201-0d532f6c0c05@googlegroups.com> <33e4862a-6fc4-4c99-9f8b-74cd388dfbef@googlegroups.com> <995425d1-0f9f-4086-b02c-9a48910336b4@googlegroups.com> <5861f87d-0660-44af-ba33-3b5f00a76508@googlegroups.com> <81267d1a-e9c6-4831-87f2-f6cf5248a7c5@googlegroups.com> <56159862.10802@verizon.net> <869ba0c3-93c1-4ec0-9454-a83d7aa0b81c@googlegroups.com> <04a9dae0-29bb-4e83-9608-5a2b2e36b004@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx02.eternal-september.org; posting-host="945944de09706c9b4e29b53c9d2efdc2"; logging-data="15406"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/N/4GJ9UIfqSIO91dvJ570" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:OeWStssL5v1bRYSrUj/M4TAqXRs= sha1:ofHy3Bjh/VOucI4Kpfk+bb7YrJA= Xref: csiph.com comp.lang.c:72205 supercat@casperkitty.com writes: > On Wednesday, October 7, 2015 at 6:33:18 PM UTC-5, Keith Thompson wrote: >> Yes. malloc() is a standard library function, and its behavior is >> defined by the standard. The behavior of attempting to modify p[10] is >> not defined by the standard (though of course an implementation is free >> to document the behavior if it likes). > > If the library documents the behavior of "malloc", "free", etc. in greater > detail than required by the Standard, and such documentation implies that > modifying certain bytes immediately outside the allocation will have > particular effects, would there be any standard means to ensure that a > compiler would honor the semantics of the library? No, why would there be? A conforming implementation is free to document whatever it likes, and to behave in any way it likes within the rules set by the standard. Enforcement of an implementation's non-standard documentation is outside the scope of the standard. I suppose a future C standard could add a rule requiring implementations to conform to their own documentation, but I see no point in doing so. If an implementation violates its own documentation, it's a bug, and you can complain to the vendor. -- 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"