Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | Keith Thompson <kst-u@mib.org> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: sizeof on an uninitialized pointer to a VLA |
| Date | 2015-11-21 03:26 -0800 |
| Organization | None to speak of |
| Message-ID | <lnbnan8uf7.fsf@kst-u.example.com> (permalink) |
| References | (1 earlier) <n2ljik$iqo$1@dont-email.me> <ln610wevm8.fsf@kst-u.example.com> <87mvu8rbor.fsf@bsb.me.uk> <lnsi40axv9.fsf@kst-u.example.com> <871tbjpr4m.fsf@bsb.me.uk> |
Ben Bacarisse <ben.usenet@bsb.me.uk> writes:
> Keith Thompson <kst-u@mib.org> writes:
[...]
>> 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.
Are you thinking that "constant" means "read-only"? That's "const",
which is not at all the same thing as "constant".
The word "constant" means, basically, "evaluated at compile time".
Specifically a constant expression is one that can be evaluated at
compile time; the full definition is in N1570 6.6.
1+1 is a constant expression; n+1 is not (unless n is an enumeration
constant).
*A* constant is a lexical element, such as 42, 1.5, or '?'.
`sizeof expression` and `sizeof ( type-name )` are both unary
expressions. A better formulation, I think, is:
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 unary expression is an integer
constant expression unless the type of the operand is a variable
length array type.
This covers all 4 cases:
1. sizeof vla_expr
Not a constant expression, but the operand is not evaluated.
This differs from what the standard currently says.
2. sizeof ( vla_type )
Not a constant expression. Any expressions that are part of the type
name are evaluated
3. sizeof non_vla_expr
This is a constant expression. The operand is not evaluated.
4. sizeof ( non_vla_type )
This is a constant expression. Any expressions that are part of the
type name are evaluated -- but since they can only be constant
expressions, there are no side effects. (Consider `sizeof ( int[10] )`;
10 is evaluated at compile time.)
--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
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"
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