Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #148301
| From | Keith Thompson <kst-u@mib.org> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: sizeof object got by dereferencing uniniitalized pointer |
| Date | 2019-11-29 13:15 -0800 |
| Organization | None to speak of |
| Message-ID | <lntv6m1j1k.fsf@kst-u.example.com> (permalink) |
| References | (9 earlier) <87v9r33211.fsf@bsb.me.uk> <861rtr8ndf.fsf@linuxsc.com> <Hb%DF.30271$s93.29962@fx19.iad> <lnlfrzulg0.fsf@kst-u.example.com> <Zy9EF.120213$P37.66802@fx33.iad> |
Richard Damon <Richard@Damon-Family.org> writes:
> On 11/29/19 3:38 AM, Keith Thompson wrote:
>> Richard Damon <Richard@Damon-Family.org> writes:
>> [...]
>>> I had always read the phrase from 6.5.3.4p2
>>>
>>> The sizeof operator yields the size (in bytes) of its operand, which may
>>> be an expression or the parenthesized name of a type. The size is
>>> determined from the type of the operand. The result is an integer. 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.
>>>
>>> As referring to if the operand WAS a variable length array type, but the
>>> wording doesn't quite say that. My guess is that is what was intended.
>>
>> I *think* you're saying that the "operand is evaluated" clause is meant
>> to apply to `sizeof (vla_type)` but not to `sizeof vla_object`. Is that
>> what you meant? I don't agree that that's what the wording in the
>> standard says, but I do agree that it could be a more reasonable rule.
[...]
> Yes, I agree that isn't what it SAYS, but it could be what they meant to
> say, but didn't word it right, for some of the reasons you mention.
That doesn't seem plausible to me. The current wording explicitly says
that `sizeof vla_expression` evaluates `vla_expression`. I think it
would have been worded quite differently if the evaluation were meant to
apply only to an operand that's a parenthesized type name. Multiple
compilers generate code that evaluates the expression, examples (some
contrived) are well known, and as far as I know nobody on the committee
has spoken up to say "That's not what we meant".
It's plausible that the rule *could* be that `sizeof vla_expression`
doesn't evaluate `vla_expression`, but I don't think it's plausible that
the committee didn't intend `vla_expression` to be evaluated (though
it's possible they didn't sufficiently think through what that means).
> Yes, we don't evaluate a type, but a variable modified type by
> definition has an expression in it that isn't a constant, so needs to be
> evaluated, and that would need to be evaluated by sizeof.
To be clear, it's not the *type* that has an expression in it, it's the
*type-name* that's the operand (in parentheses) of the sizeof operator.
> Also, generally the type of an expression is easily known even without
> knowing the value of any of the objects in an expression, which is what
> I think they meant to use in the statement.
That's true "generally"in the sense that it's *usually* known, but not
"generally" in the sense that it's *always* known. And of course the
standard has to cover all defined cases.
> I think there may be a way
> to use a compound literal expression to create a new type in an
> expression, and then that type would need to be 'evaluated'
Not directly, since the type name in a compound literal cannot be a VLA
type. But as Tim points out, it can be done by dereferencing a compound
literal of a pointer-to-VLA type.
--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
Working, but not speaking, for Philips Healthcare
void Void(void) { Void(); } /* The recursive call of the void */
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
sizeof object got by dereferencing uniniitalized pointer "V.Subramanian, India" <subramanian100in@yahoo.com> - 2019-11-28 05:20 -0800
Re: sizeof object got by dereferencing uniniitalized pointer Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2019-11-28 05:37 -0800
Re: sizeof object got by dereferencing uniniitalized pointer mark.bluemel@gmail.com - 2019-11-28 05:59 -0800
Re: sizeof object got by dereferencing uniniitalized pointer David Brown <david.brown@hesbynett.no> - 2019-11-28 15:51 +0100
Re: sizeof object got by dereferencing uniniitalized pointer Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2019-11-28 07:27 -0800
Re: sizeof object got by dereferencing uniniitalized pointer Herbert Rosenau <nospam@hrosenau.de> - 2019-11-28 17:28 +0100
Re: sizeof object got by dereferencing uniniitalized pointer Thiago Adams <thiago.adams@gmail.com> - 2019-11-28 08:51 -0800
Re: sizeof object got by dereferencing uniniitalized pointer Ben Bacarisse <ben.usenet@bsb.me.uk> - 2019-11-28 17:36 +0000
Re: sizeof object got by dereferencing uniniitalized pointer Tim Rentsch <tr.17687@z991.linuxsc.com> - 2019-11-28 16:37 -0800
Re: sizeof object got by dereferencing uniniitalized pointer Ben Bacarisse <ben.usenet@bsb.me.uk> - 2019-11-29 01:27 +0000
Re: sizeof object got by dereferencing uniniitalized pointer Tim Rentsch <tr.17687@z991.linuxsc.com> - 2019-11-28 17:47 -0800
Re: sizeof object got by dereferencing uniniitalized pointer Richard Damon <Richard@Damon-Family.org> - 2019-11-28 21:16 -0500
Re: sizeof object got by dereferencing uniniitalized pointer Keith Thompson <kst-u@mib.org> - 2019-11-29 00:38 -0800
Re: sizeof object got by dereferencing uniniitalized pointer Richard Damon <Richard@Damon-Family.org> - 2019-11-29 09:03 -0500
Re: sizeof object got by dereferencing uniniitalized pointer Keith Thompson <kst-u@mib.org> - 2019-11-29 13:15 -0800
Re: sizeof object got by dereferencing uniniitalized pointer Keith Thompson <kst-u@mib.org> - 2019-11-29 13:38 -0800
Re: sizeof object got by dereferencing uniniitalized pointer Tim Rentsch <tr.17687@z991.linuxsc.com> - 2019-11-29 07:09 -0800
Re: sizeof object got by dereferencing uniniitalized pointer Tim Rentsch <tr.17687@z991.linuxsc.com> - 2019-11-29 06:10 -0800
Re: sizeof object got by dereferencing uniniitalized pointer Richard Damon <Richard@Damon-Family.org> - 2019-11-29 11:12 -0500
Re: sizeof object got by dereferencing uniniitalized pointer Tim Rentsch <tr.17687@z991.linuxsc.com> - 2019-12-01 09:32 -0800
Re: sizeof object got by dereferencing uniniitalized pointer Tim Rentsch <tr.17687@z991.linuxsc.com> - 2019-11-29 07:39 -0800
Re: sizeof object got by dereferencing uniniitalized pointer Ben Bacarisse <ben.usenet@bsb.me.uk> - 2019-11-29 22:00 +0000
Re: sizeof object got by dereferencing uniniitalized pointer Richard Damon <Richard@Damon-Family.org> - 2019-11-29 22:40 -0500
Re: sizeof object got by dereferencing uniniitalized pointer Ben Bacarisse <ben.usenet@bsb.me.uk> - 2019-11-30 11:19 +0000
Re: sizeof object got by dereferencing uniniitalized pointer Richard Damon <Richard@Damon-Family.org> - 2019-11-30 09:01 -0500
Re: sizeof object got by dereferencing uniniitalized pointer Tim Rentsch <tr.17687@z991.linuxsc.com> - 2019-12-01 10:28 -0800
Re: sizeof object got by dereferencing uniniitalized pointer Richard Damon <Richard@Damon-Family.org> - 2019-11-28 12:49 -0500
Re: sizeof object got by dereferencing uniniitalized pointer Thiago Adams <thiago.adams@gmail.com> - 2019-11-28 11:26 -0800
Re: sizeof object got by dereferencing uniniitalized pointer Richard Damon <Richard@Damon-Family.org> - 2019-11-28 17:19 -0500
Re: sizeof object got by dereferencing uniniitalized pointer Tim Rentsch <tr.17687@z991.linuxsc.com> - 2019-11-28 17:26 -0800
Re: sizeof object got by dereferencing uniniitalized pointer Ben Bacarisse <ben.usenet@bsb.me.uk> - 2019-11-28 22:34 +0000
Re: sizeof object got by dereferencing uniniitalized pointer Ben Bacarisse <ben.usenet@bsb.me.uk> - 2019-11-28 17:34 +0000
You gotta wonder why people say things like this! (Was: sizeof object got by dereferencing uniniitalized pointer) gazelle@shell.xmission.com (Kenny McCormack) - 2019-11-28 17:19 +0000
Re: sizeof object got by dereferencing uniniitalized pointer Keith Thompson <kst-u@mib.org> - 2019-11-28 14:55 -0800
Re: sizeof object got by dereferencing uniniitalized pointer "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2019-11-30 15:28 -0800
csiph-web