Path: csiph.com!eternal-september.org!feeder.eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: Future of C Date: Tue, 13 Mar 2018 13:39:57 -0700 Organization: None to speak of Lines: 57 Message-ID: References: <0231327b-9e28-46e4-9178-46c881a8dd91@googlegroups.com> <20180310180016.eda9bc36e1a3b182bc2563a8@gmail.com> <20180311000302.8e7cd15242a818ab75eb2e98@gmail.com> <83527acf-abed-4f8f-878c-7d4db9cd5ac1@googlegroups.com> <20180311161525.ac591de531b83d6b14b2cd43@gmail.com> <90236828-48d7-4ee5-9b86-4cedd0e29b5f@googlegroups.com> <3r7jne-t3h.ln1@gangtai.grep.be> <8e201938-ada4-42d9-8ae6-13b1047306e2@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: reader02.eternal-september.org; posting-host="a9638e2b58572a27edc6516887e5eee0"; logging-data="21725"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18D4edVhTDN6IPNST4i2WoZ" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:coi4uwOiuw6he4LEvG/ubxefKW8= sha1:Ur0ZV78eFt69ojLpy3SR4d6ADEo= Xref: csiph.com comp.lang.c:127772 David Brown writes: [...] > When something like "int vs[n];" comes into scope, you know the value of > n - either it is fixed at compile time, or it is a variable (treatable > as size_t). You allocate space for sizeof(int) * n bytes on the stack - > this is likely to be the assembly for "sp = sp - 4 * n;". > > It is /exactly/ like "int vs[N];" where N is a literal integer value, or > a #define'd name expanding to a literal integer value. The difference, > if any, is that you might need "n" in a register instead of as a literal. You need to store the value of n (or of n * sizeof vs[0]) somewhere, so that `sizeof vs` works correctly. (That's not difficult.) > There is some scope for complication with the kind of horrors James has > constructed with labels, jumping back and forth over the declaration, > etc. There is a fair case to be made for simply rejecting such code > with an error message - you will technically be non-conforming, but no > real code will be harmed. > > Note that 6.7p4 "All declarations in the same scope that refer to the > same object or function shall specify compatible types" - re-running the > same declaration using gotos and labels cannot result in a different > size of VLA. 6.8.6.1p1: Constraints ... A goto statement shall not jump from outside the scope of an identifier having a variably modified type to inside the scope of that identifier. (I haven't looked at the code in question closely enough to know whether any of it violates that.) > I am truly at a loss to imagine how one could find this so hard - > assuming you already have a C99 compiler that handles mixed declarations > and statements, block scopes, etc. (/That/ is hard - all I am saying is > that adding VLA's is not a big burden once you have everything else.) > > I am sure there are plenty of details to take care of. And there are > some oddities with VLA's - if you write "int vs[foo()];", then when you > later write "int n = sizeof(vs);" you have to re-evaluate foo and might > give a result that is not actually the size of "vs". So you generate > the same code here as if the use had written "int n = 4 * foo();". > Again, this is not /hard/ because you have already done it. No, evaluating `sizeof vs` does *not* re-evaluate `foo()`. [...] -- 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"