Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: sizeof on an uninitialized pointer to a VLA |
| Date | 2015-11-21 10:46 +0000 |
| Organization | A noiseless patient Spider |
| Message-ID | <871tbjpr4m.fsf@bsb.me.uk> (permalink) |
| References | <5e03af2c-3c3e-4432-bf5a-000867e5febb@googlegroups.com> <n2ljik$iqo$1@dont-email.me> <ln610wevm8.fsf@kst-u.example.com> <87mvu8rbor.fsf@bsb.me.uk> <lnsi40axv9.fsf@kst-u.example.com> |
Keith Thompson <kst-u@mib.org> writes: > Ben Bacarisse <ben.usenet@bsb.me.uk> writes: <snip> >> If we replace *arr with arr[0] but with the 0 being produced by a >> function call: >> >> sizeof arr[f()] >> >> then the wording says that f must be called. gcc obliges but clang does >> not. <snip example> > The output using every version of gcc and clang I've tried is: > > zero() > sizeof vla[zero()] = 10 And I've just tried to see how I determined that clang did not evaluate the argument to sizeof and I could not. I don't know why I thought it didn't but I agree that gcc clang to the same with your example (and now, it seems, with mine!). <snip> >> As you say, the intent may well have been to limit evaluation to >> expressions contained in type names of VLAs, but it certainly doesn't >> say that, and at least one implementation has taken the literal meaning. >> >> Maybe rather than this: >> >> "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." >> >> what was meant was this: >> >> "If the operand is a variable length array type name, any expressions >> in the operand are evaluated; otherwise, the operand is not evaluated >> and the result is an integer constant." > > The result of `sizeof vla_object` is not an integer constant. (Aside: > "integer constant" is a poor choice of words, since that phrase has a > different meaning.) Agreed. > The type of the operand to sizeof is known at compile time, and > I believe that the size of that type can always be determined > without evaluating anything other than the values of anonymous > compiler-generated objects (or whatever mechanism the implementation > uses to remember the size of a VLA type). > > I suggest something like: > > If the operand is a parenthesized variable length array type name, > any expressions in the operand are evaluated. Otherwise, the > operand is not evaluated. The result is constant unless the > type of the operand is a variable length array type. I find the idea that the result of an expression might be anything but constant rather odd. Would "The result is *a* constant" be better? But then does the last sentence add anything very useful? I'd be inclined to omit it. -- Ben.
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
sizeof on an uninitialized pointer to a VLA John Bode <jfbode1029@gmail.com> - 2015-11-19 11:39 -0800
Re: sizeof on an uninitialized pointer to a VLA supercat@casperkitty.com - 2015-11-19 12:09 -0800
Re: sizeof on an uninitialized pointer to a VLA "A. Bolmarcich" <aggedor@earl-grey.cloud9.net> - 2015-11-19 21:40 +0000
Re: sizeof on an uninitialized pointer to a VLA supercat@casperkitty.com - 2015-11-19 13:50 -0800
Re: sizeof on an uninitialized pointer to a VLA James Kuyper <jameskuyper@verizon.net> - 2015-11-19 17:50 -0500
Re: sizeof on an uninitialized pointer to a VLA supercat@casperkitty.com - 2015-11-19 15:31 -0800
Re: sizeof on an uninitialized pointer to a VLA Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-11-20 01:09 +0000
Re: sizeof on an uninitialized pointer to a VLA supercat@casperkitty.com - 2015-11-19 19:10 -0800
Re: sizeof on an uninitialized pointer to a VLA Keith Thompson <kst-u@mib.org> - 2015-11-20 03:52 -0800
Re: sizeof on an uninitialized pointer to a VLA Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-11-20 14:24 +0000
Re: sizeof on an uninitialized pointer to a VLA supercat@casperkitty.com - 2015-11-20 10:25 -0800
Re: sizeof on an uninitialized pointer to a VLA Keith Thompson <kst-u@mib.org> - 2015-11-20 18:29 -0800
Re: sizeof on an uninitialized pointer to a VLA Ian Collins <ian-news@hotmail.com> - 2015-11-21 16:35 +1300
Re: sizeof on an uninitialized pointer to a VLA Keith Thompson <kst-u@mib.org> - 2015-11-20 20:24 -0800
Re: sizeof on an uninitialized pointer to a VLA Ian Collins <ian-news@hotmail.com> - 2015-11-21 17:38 +1300
Re: sizeof on an uninitialized pointer to a VLA Keith Thompson <kst-u@mib.org> - 2015-11-20 21:08 -0800
Re: sizeof on an uninitialized pointer to a VLA Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-11-21 10:46 +0000
Re: sizeof on an uninitialized pointer to a VLA Keith Thompson <kst-u@mib.org> - 2015-11-21 03:26 -0800
Re: sizeof on an uninitialized pointer to a VLA Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-11-21 12:46 +0000
Re: sizeof on an uninitialized pointer to a VLA Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-11-21 14:01 +0000
Re: sizeof on an uninitialized pointer to a VLA supercat@casperkitty.com - 2015-11-21 09:02 -0800
Re: sizeof on an uninitialized pointer to a VLA Keith Thompson <kst-u@mib.org> - 2015-11-21 12:09 -0800
csiph-web