Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | Shao Miller <sha0.miller@gmail.com> |
|---|---|
| Newsgroups | comp.std.c |
| Subject | Re: What does it mean to evaluate a VLA? |
| Date | 2012-12-18 21:09 -0500 |
| Organization | A noiseless patient Spider |
| Message-ID | <kar7lo$5dk$1@dont-email.me> (permalink) |
| References | <lnr4mmrftq.fsf@nuthaus.mib.org> |
On 12/18/2012 20:28, Keith Thompson wrote:
> N1370 6.5.3.4p2, discussing the sizeof operator, says:
>
> 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 does it mean to "evaluate" the operand of sizeof when it's of a
> variable length array type?
>
I think it means to evaluate it as a void expression, for its side effects.
I would be startled if:
size_t sz = sizeof (func1(), (int[func2()]){0});
didn't evaluate 'func1', which might influence the output of 'func2'.
(Untested.)
> An example:
>
> int n = 42;
> volatile int vla[n];
> printf("sizeof vla = %zu\n", sizeof vla);
>
I think the element type is 'volatile', not the array[C11 6.7.3p9].
It's still interesting that if the "as a void expression" theory above
is correct, "nothing happens" for 'vla' here, because it's an array and
an operand to 'sizeof', so not even a pointer value need be computed
(else 'register' could go wrong).
But there's another situation where evaluation seems to happen despite
apparent suppression:
size_t sz = sizeof *( 0 ? 0 : (int(*)[myfunc()]) 0 );
The ternary's third operand "isn't evaluated," but because its type
needs to be determined, those portions required for that determination
are. In this case, 'myfunc' is called.
I like to imagine that expressions are split into at least "type" and
"value," and evaluation for the determination of one may be separate
from evaluation for purposes of the other. I think the non-VLA 'sizeof'
case suppresses evaluations for value, but doesn't suppress those for type:
size_t sz = sizeof (int[42 ? 1 : 3]);
- Shao Miller
Back to comp.std.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
What does it mean to evaluate a VLA? Keith Thompson <kst-u@mib.org> - 2012-12-18 17:28 -0800
Re: What does it mean to evaluate a VLA? Shao Miller <sha0.miller@gmail.com> - 2012-12-18 21:09 -0500
Re: What does it mean to evaluate a VLA? Shao Miller <sha0.miller@gmail.com> - 2012-12-20 03:52 -0500
Re: What does it mean to evaluate a VLA? Shao Miller <sha0.miller@gmail.com> - 2012-12-20 04:08 -0500
Re: What does it mean to evaluate a VLA? Tim Rentsch <txr@alumni.caltech.edu> - 2012-12-20 20:43 -0800
Re: What does it mean to evaluate a VLA? Shao Miller <sha0.miller@gmail.com> - 2012-12-21 05:01 -0500
Re: What does it mean to evaluate a VLA? Tim Rentsch <txr@alumni.caltech.edu> - 2012-12-21 08:55 -0800
csiph-web