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: Array allocated on stack or heap Date: Fri, 17 Mar 2017 17:08:36 -0700 Organization: None to speak of Lines: 34 Message-ID: References: <5d66219a-4bf3-42a6-855d-4dfe9e900149@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx02.eternal-september.org; posting-host="953e254308ea5d79b385d87825e2e8df"; logging-data="15061"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/RRFYOjc81yDvgwH6bqJlC" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:2jsKrMb1TvAzeQZW+BNblXaw/nw= sha1:+kTwMvjYE7IYgfrYBfFwhred1Ik= Xref: csiph.com comp.lang.c:106416 jameskuyper@verizon.net writes: > On Friday, March 17, 2017 at 7:13:06 PM UTC-4, jacobnavia wrote: > ... >> True, nobody is discussing that. But when speaking about C it is >> important to explain this feature in a manner that is easy to undertsnad >> and corresponds to the majority of machines we are going to use. > > True, but it's also important to avoid explaining the feature in a > manner that can lead to the misunderstanding that all machines work > the same way as the most common machines. It's easy for people to > acquire the delusion that all systems behave the same way as the ones > they're most familiar with. To fight that delusion it's essential that > the existence of other ways of doing things be frequently > acknowledged, and when relevant, explained. And someone who thinks that all C implementations use a contiguous hardware stack might be tempted to write code that relies on that assumption, for example comparing addresses to determine how far up or down the stack they are. That kind of knowledge can be handy for debugging, but it's a bad idea to depend on it even if it happens to be true for the current implementation (among other things, it's UB). All you really need to know to write good C code is that automatic allocation occurs in a last-in first-out manner. Admittedly some programmers might prefer a more concrete mental model, but IMHO it's a good idea to keep in mind which details of that model are actually guaranteed by the language and which aren't. -- 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"