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: Dinamic array without malloc - Can be done? Date: Mon, 16 Jan 2017 09:22:05 -0800 Organization: None to speak of Lines: 26 Message-ID: References: <863e4550-027a-4d32-b5df-e34f2c7b4439@googlegroups.com> <01610cdf-e6ca-47ac-ba40-b597b0c524d0@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx02.eternal-september.org; posting-host="0a2d73b4260c7d84c3fe58a86676df00"; logging-data="32497"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18wwG8iUrItZbQIIK4lWH8c" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:MRdtJ7kooJJU1VlTmltCn6r7Z08= sha1:rSMG/PXEYtql9B5Ewb0HIHGN0J0= Xref: csiph.com comp.lang.c:101988 David Brown writes: [...] > IMHO, alloca and VLA are no worse than many other things in C - you > simply have to know what you are doing and be sure you are doing things > properly, such as checking the size before allocation. [...] I agree, mostly. But alloca and VLAs make it easier (relative to fixed-size arrays) to overflow the stack by accidentally allocating a very large chunk of memory. Given: { size_t n = some_computation; double vla[n]; } it can be arbitrarily difficult to avoid overflow, and to perform static analysis of how much the stack can grow. The solution, as with most things, is "be careful". -- 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"