Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!news.musoftware.de!wum.musoftware.de!border1.nntp.ams2.giganews.com!border3.nntp.ams.giganews.com!Xl.tags.giganews.com!border1.nntp.ams.giganews.com!nntp.giganews.com!local2.nntp.ams.giganews.com!nntp.brightview.co.uk!news.brightview.co.uk.POSTED!not-for-mail NNTP-Posting-Date: Wed, 27 Jun 2012 01:25:10 -0500 From: Gareth Owen Newsgroups: comp.lang.c Subject: Re: Variable-length arrays: should they be used at all? References: Date: Wed, 27 Jun 2012 07:25:10 +0100 Message-ID: <87mx3p9sqh.fsf@gmail.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:4u+UGGqMIMYbnLDqDcbOb7MkpmQ= MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Lines: 21 X-Usenet-Provider: http://www.giganews.com X-Trace: sv3-ofYWNigFjKXdrEoaym/nfAlkNtcnKMlws0a5uHhhEXM/y+7kbFKTGKHqBCxQVfhRd6xX8vIgQG4XJM8!i74oQVz3KMK8QfHKlYCmMtIDKPMQYM9m3D9Dl9RMk/vL82xtMfwPGj1P3ypsDKICgkuY X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.40 X-Original-Bytes: 1873 Xref: csiph.com comp.lang.c:22848 Keith Thompson writes: > But the same applies to old-style constant-size arrays. If you declare > > double mat[100][100]; > > either at block scope I think at block scope most people would consider that a pretty bad idea, for exactly the same reason. But at least you have the potential to do static analysis to check the necessary stack size. > or at file scope, At file scope, one would certainly hope that this would cause the program would crash *at startup*. (I appreciate this isn't guaranteed), and, again, static analysis would tell you the minimum RAM required. In the embedded case, any decent compiler will tell you whether your static data is going to eat all your RAM. Both of which are arguably better than UB based on input size.