Path: csiph.com!news.swapon.de!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: A glitch regarding the usual malloc() idiom Date: Wed, 20 Jul 2016 08:59:49 -0700 Organization: None to speak of Lines: 36 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx02.eternal-september.org; posting-host="945944de09706c9b4e29b53c9d2efdc2"; logging-data="6137"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+6kmeCvq2Ncjyzs6mzy5kX" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:YcbXUIP6aOxSU7edZzx808bLmtE= sha1:lsWt2GiTai29IhjoEh+5Qwbc0Gs= Xref: csiph.com comp.lang.c:90665 Udyant Wig writes: > On 07/20/2016 04:00 AM, Keith Thompson wrote: >> [intriguing observation] > > Thanks for the intriguing observation. I read up Harbison and Steele > on sizeof where they have one paragraph on this that makes for > interesting reading: > > If a variable length array type name appears in a sizeof expression and > the value of the array size affects the value of the sizeof expression, > then the array size expression is always fully evaluated, including side > effects. If the value of the array size does not affect the result of > the sizeof, then it is undefined whether the size expression is > evaluated. That would probably be a sensible rule, but it's not what the standard says. N1570 6.5.3.4p2: If the type of the operand is a variable length array type, the operand is evaluated; otherwise, the operand is not evaluated and the result is an integer constant. That still leaves some open questions (which have been discussed at some length). The phrase "integer constant" is used incorrectly. An "integer constant" is by definition a decimal, octal, or hexadecimal constant. It should say "integer constant expression". -- 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"