Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #16741

Re: Size of an arraylist in bytes

From Kaz Kylheku <kaz@kylheku.com>
Newsgroups comp.lang.c
Subject Re: Size of an arraylist in bytes
Date 2012-02-06 08:46 +0000
Organization A noiseless patient Spider
Message-ID <20120206090944.825@kylheku.com> (permalink)
References (14 earlier) <kfnsjivz2sa.fsf@x-alumni2.alumni.caltech.edu> <lnzkd2te2w.fsf@nuthaus.mib.org> <eketv8-fdf.ln1@jones.homeip.net> <20120203135041.829@kylheku.com> <jgnmqa$8lv$1@dont-email.me>

Show all headers | View raw


On 2012-02-06, Shao Miller <sha0.miller@gmail.com> wrote:
> On 2/3/2012 17:35, Kaz Kylheku wrote:
>>
>> A very simple, define an lvalue is as an expression which satisfies these three
>> conditions:
>>
>> - [lvalue syntactic form] An lvalue is either a certain kind of primary
>>    expression, (identifier or string literal) or its operator falls into a
>>    certain set:
>>    - struct/union member selection (. operator) applied to an expression which
>>      itself has lvalue syntactic form).
>>    - pointer member selection (->  operator)
>>    - pointer dereference or array indexing
>>    If E has the syntactic form of an lvalue, then so does (E) and
>>    denotes the same lvalue as E.
>>
>
>
> Huh?
>
> '.' and '->' and '[]' have two operands.  When you say "its operator," 
> do you really mean when it's either the left or right operand of these?

No, I mean the operator of the expression. Each expression has some main
operator: the thing that we would put on the left in a bracket notation
for the abstract syntax tree (Lisp style). For instance a[b+c] could have
an AST node that could be notated ([] a (+ b c)). The [] symbol is the main
operator of the expression, and not +.

> The first point appears to be circular: An expression is an lvalue if it 
> is an operand to the '.' operator and that operator's operand (which 

No, an expression has the syntactic form of an lvalue if it is a member
selection expression like a.b. We are concerned about a.b, not a.

> What about compound literals?

Lvalues. I've left a lot of "etc."

>> And note how it is not necessary to inherit the lvalue attribute semantically.
>> According to standard C, f().d cannot be an lvalue because the struct returned
>> by f() is not an lvalue, and x.y is only an lvalue if x is.  According to the
>> above rules, however, f().d is not an lvalue simply because, although it is
>> a member selection, the base expression f() lacks lvalue syntactic form.
>> (If you can determine an attribute purely from syntax, there is no need
>> to compute it inheritance of abstract attributes!)
>>
>
> If I understand the syntactic form you've given above, then given:
>
>    enum foo { bar };
>
> 'foo' is syntactically an lvalue and 'foo.blecch' is syntactically an 

foo is syntactically an lvalue (according to my proposed rules, for the benefit
of readers jumping in mid-thread, and not according to standard C) if it is a
primary expression. foo is not a primary expression in ``enum foo''. It
is an enum label, involved in a declaration.

> lvalue and 'bar' is syntactically an lvalue and 'bar.blecch' is 
> syntactically an lvalue?
>
> And for the '->' operator, the '42' in '42->blecch' is syntactically an 
> lvalue?

No, an integer constant isn't. It is neither the right kind of primary
expression, nor is it one of the expression kinds like dereferencing, etc.

42->blecch could be considered syntactically an lvalue because it has a
suitable kind of operator.  

But then it fails on account of the expresion being nonsense and requiring a
diagnostic. (We do not have to define lvalues such that they reject this kind
of thing; that complicates the language with redundancy.)

> Then to establish context:
> - The 'foo' in '&foo' is contextually and syntactically an lvalue

It is now, but of course this foo does not refer to the enum tag foo.

> - The 'foo.blecch' in '&foo.blecch' is contextually and syntactically an 
> lvalue

Clearly, and so all that remains is for foo.blecch to make sense.

> - The '42->blecch' in '&42->blecch' is contextually and syntactically an 
> lvalue

As I have defined the rules, yes. If those rules are applied first, before
the translator verifies whether 42->blech makes sense, it will have to label
the 42->blech as an lvalue candidate satisfying the first two properties:
syntactic form and context. The type determination cannot be made without
resolving ->blech, and that requires a pointer to an aggregate that has a
member whose name is blech.

So at some point it will have to conclude that the expression is not well
formed and emit a diagnostic (and possibly supply a bizarre extension of
behavior that allows 42->blech, and even allows it to remain an lvalue.)

> So what if we have:
>
>    enum foo { bar };
>    char foo;
>
> Now when we are considering '&foo', it's contextually and syntactically 
> an lvalue, but for the type consideration, are we considering the 'enum' 
> type or the 'char' object?

Of course the char object. The type of the subexpression foo in the expression
&foo is char. It is a primary expression referring to the object char foo.

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Re: Size of an arraylist in bytes Joe Wright <joewwright@comcast.net> - 2011-11-21 16:25 -0500
  Re: Size of an arraylist in bytes Keith Thompson <kst-u@mib.org> - 2011-11-21 14:03 -0800
    Re: Size of an arraylist in bytes pete <pfiland@mindspring.com> - 2011-11-21 17:45 -0500
      Re: Size of an arraylist in bytes Ark <akhasin@macroexpressions.com> - 2011-11-21 21:19 -0500
        Re: Size of an arraylist in bytes Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-11-21 22:06 -0500
          Re: Size of an arraylist in bytes Ark <akhasin@macroexpressions.com> - 2011-11-22 03:07 -0500
            Re: Size of an arraylist in bytes James Kuyper <jameskuyper@verizon.net> - 2011-11-22 06:51 -0500
        Re: an instance of an object (was: Size of an arraylist in bytes) Keith Thompson <kst-u@mib.org> - 2011-11-21 21:54 -0800
        Re: Size of an arraylist in bytes pete <pfiland@mindspring.com> - 2011-11-22 01:49 -0500
          Re: Size of an arraylist in bytes Ark <akhasin@macroexpressions.com> - 2011-11-22 03:17 -0500
            Re: Size of an arraylist in bytes Keith Thompson <kst-u@mib.org> - 2011-11-22 00:48 -0800
            Re: Size of an arraylist in bytes pete <pfiland@mindspring.com> - 2011-11-23 05:16 -0500
          Re: Size of an arraylist in bytes Kaz Kylheku <kaz@kylheku.com> - 2011-11-22 16:49 +0000
        Re: Size of an arraylist in bytes pete <pfiland@mindspring.com> - 2011-11-23 09:30 -0500
  Re: Size of an arraylist in bytes Nick Keighley <nick_keighley_nospam@hotmail.com> - 2011-11-22 00:07 -0800
    Re: Size of an arraylist in bytes Keith Thompson <kst-u@mib.org> - 2011-11-22 00:24 -0800
      Re: Size of an arraylist in bytes Tim Rentsch <txr@alumni.caltech.edu> - 2012-01-25 05:06 -0800
        Re: Size of an arraylist in bytes Keith Thompson <kst-u@mib.org> - 2012-01-25 12:15 -0800
          Re: Size of an arraylist in bytes Tim Rentsch <txr@alumni.caltech.edu> - 2012-01-31 18:49 -0800
            Re: Size of an arraylist in bytes Keith Thompson <kst-u@mib.org> - 2012-02-01 13:53 -0800
              Re: Size of an arraylist in bytes lawrence.jones@siemens.com - 2012-02-01 18:53 -0500
                Re: Size of an arraylist in bytes Keith Thompson <kst-u@mib.org> - 2012-02-01 20:06 -0800
              Re: Size of an arraylist in bytes Shao Miller <sha0.miller@gmail.com> - 2012-02-01 21:40 -0500
                Re: Size of an arraylist in bytes jgk@panix.com (Joe keane) - 2012-02-02 03:45 +0000
                Re: Size of an arraylist in bytes Keith Thompson <kst-u@mib.org> - 2012-02-01 20:14 -0800
                Re: Size of an arraylist in bytes Eric Sosman <esosman@ieee-dot-org.invalid> - 2012-02-01 23:14 -0500
                Re: Size of an arraylist in bytes Shao Miller <sha0.miller@gmail.com> - 2012-02-02 18:38 -0500
                Re: Size of an arraylist in bytes jgk@panix.com (Joe keane) - 2012-02-03 16:32 +0000
                Re: Size of an arraylist in bytes James Kuyper <jameskuyper@verizon.net> - 2012-02-03 11:57 -0500
                Re: Size of an arraylist in bytes Shao Miller <sha0.miller@gmail.com> - 2012-02-03 20:07 -0500
                Re: Size of an arraylist in bytes jgk@panix.com (Joe keane) - 2012-02-04 22:35 +0000
                Re: Size of an arraylist in bytes James Kuyper <jameskuyper@verizon.net> - 2012-02-04 18:43 -0500
                Re: Size of an arraylist in bytes Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-02-05 01:50 +0000
                Re: Size of an arraylist in bytes James Kuyper <jameskuyper@verizon.net> - 2012-02-04 21:37 -0500
                Re: Size of an arraylist in bytes Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-02-05 14:48 +0000
                Re: Size of an arraylist in bytes James Kuyper <jameskuyper@verizon.net> - 2012-02-05 10:20 -0500
                Re: Size of an arraylist in bytes Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-02-05 16:25 +0000
                Re: Size of an arraylist in bytes James Kuyper <jameskuyper@verizon.net> - 2012-02-05 12:06 -0500
                Re: Size of an arraylist in bytes Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-02-05 19:21 +0000
                Re: Size of an arraylist in bytes Shao Miller <sha0.miller@gmail.com> - 2012-02-05 15:29 -0500
                Re: Size of an arraylist in bytes Tim Rentsch <txr@alumni.caltech.edu> - 2012-03-08 10:46 -0800
                Re: Size of an arraylist in bytes Kaz Kylheku <kaz@kylheku.com> - 2012-02-05 02:39 +0000
                Re: Size of an arraylist in bytes Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-02-05 15:17 +0000
                Re: Size of an arraylist in bytes James Kuyper <jameskuyper@verizon.net> - 2012-02-05 12:06 -0500
                Re: Size of an arraylist in bytes Shao Miller <sha0.miller@gmail.com> - 2012-02-05 15:06 -0500
                Re: Size of an arraylist in bytes jgk@panix.com (Joe keane) - 2012-02-07 17:35 +0000
                Re: Size of an arraylist in bytes Shao Miller <sha0.miller@gmail.com> - 2012-02-07 19:51 -0500
                Re: Size of an arraylist in bytes Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-02-08 01:14 +0000
                Re: Size of an arraylist in bytes Kaz Kylheku <kaz@kylheku.com> - 2012-02-05 02:31 +0000
                Re: Size of an arraylist in bytes Eric Sosman <esosman@ieee-dot-org.invalid> - 2012-02-03 21:26 -0500
                Re: Size of an arraylist in bytes Eric Sosman <esosman@ieee-dot-org.invalid> - 2012-02-03 21:31 -0500
                Re: Size of an arraylist in bytes James Kuyper <jameskuyper@verizon.net> - 2012-02-04 06:57 -0500
                Re: Size of an arraylist in bytes Kaz Kylheku <kaz@kylheku.com> - 2012-02-04 18:32 +0000
                Re: Size of an arraylist in bytes Shao Miller <sha0.miller@gmail.com> - 2012-02-05 22:51 -0500
                Re: Size of an arraylist in bytes jgk@panix.com (Joe keane) - 2012-02-04 21:25 +0000
                Re: Size of an arraylist in bytes Eric Sosman <esosman@ieee-dot-org.invalid> - 2012-02-04 17:08 -0500
                Re: Size of an arraylist in bytes Tim Rentsch <txr@alumni.caltech.edu> - 2012-03-08 10:52 -0800
                Re: Size of an arraylist in bytes James Kuyper <jameskuyper@verizon.net> - 2012-02-04 17:32 -0500
                Re: Size of an arraylist in bytes Kaz Kylheku <kaz@kylheku.com> - 2012-02-05 02:19 +0000
                Re: Size of an arraylist in bytes Eric Sosman <esosman@ieee-dot-org.invalid> - 2012-02-05 09:20 -0500
                Re: Size of an arraylist in bytes James Kuyper <jameskuyper@verizon.net> - 2012-02-05 09:42 -0500
                Re: Size of an arraylist in bytes Shao Miller <sha0.miller@gmail.com> - 2012-02-05 16:17 -0500
                Re: Size of an arraylist in bytes Zoltan Kocsi <zoltan@bendor.com.au> - 2012-02-05 17:49 +1100
                Re: Size of an arraylist in bytes Shao Miller <sha0.miller@gmail.com> - 2012-02-05 16:48 -0500
                Re: Size of an arraylist in bytes Shao Miller <sha0.miller@gmail.com> - 2012-02-05 16:52 -0500
                Re: Size of an arraylist in bytes Shao Miller <sha0.miller@gmail.com> - 2012-02-02 01:07 -0500
              Re: Size of an arraylist in bytes lawrence.jones@siemens.com - 2012-02-03 11:29 -0500
                Re: Size of an arraylist in bytes Keith Thompson <kst-u@mib.org> - 2012-02-03 12:42 -0800
                lvalue "potentially" designates an object (was Re: Size of an arraylist in bytes) Kenneth Brody <kenbrody@spamcop.net> - 2012-02-04 12:47 -0500
                Re: lvalue "potentially" designates an object (was Re: Size of an arraylist in bytes) Kaz Kylheku <kaz@kylheku.com> - 2012-02-04 18:39 +0000
                Re: Size of an arraylist in bytes lawrence.jones@siemens.com - 2012-02-04 14:46 -0500
                Re: Size of an arraylist in bytes Kaz Kylheku <kaz@kylheku.com> - 2012-02-03 22:35 +0000
                Re: Size of an arraylist in bytes Shao Miller <sha0.miller@gmail.com> - 2012-02-06 00:01 -0500
                Re: Size of an arraylist in bytes Kaz Kylheku <kaz@kylheku.com> - 2012-02-06 08:46 +0000
                Re: Size of an arraylist in bytes Shao Miller <sha0.miller@gmail.com> - 2012-02-06 23:17 -0500
            Re: Size of an arraylist in bytes lawrence.jones@siemens.com - 2012-02-01 18:34 -0500
              Re: Size of an arraylist in bytes Tim Rentsch <txr@alumni.caltech.edu> - 2012-03-08 10:54 -0800
    Re: Size of an arraylist in bytes Tim Rentsch <txr@alumni.caltech.edu> - 2012-01-25 05:00 -0800

csiph-web