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


Groups > comp.lang.c > #27597

Re: Compatibility question

From Keith Thompson <kst-u@mib.org>
Newsgroups comp.lang.c
Subject Re: Compatibility question
Date 2012-10-23 12:26 -0700
Organization None to speak of
Message-ID <lnr4opdm7m.fsf@nuthaus.mib.org> (permalink)
References (6 earlier) <2nYjPo.Krd.2aRbe@gmail.com> <lnfw56fl74.fsf@nuthaus.mib.org> <qRFu8I.lcH.7XEwQ@gmail.com> <0.5ef6d4d4944842791bc8.20121022210639BST.87pq4a9sq8.fsf@bsb.me.uk> <ap54B1.hSk.bor8X@gmail.com>

Show all headers | View raw


Steve Thompson <stevet810@gmail.com> writes:
> On Mon, Oct 22, 2012 at 09:06:39PM +0100, Ben Bacarisse wrote:
[...]
>> Whatever goes on under the hood (and I'd dispute that 'a' is "really a
>> pointer") it's much easier to learn a language in its own terms, at
>> least as far as that's possible.
>
> Well, no.  'a' is never a pointer as such in the terms of the language
> syntax, but its treatment by the compiler internally is nominally
> equivalent to they way it handles a pointer, with the exception that
> the language grammar forbids its use in the program text as a pointer.

I don't believe that's true.  Do you have some evidence that it is?

> In a simplistic sense, all variables are pointers to a segment of
> program data, modifiable or otherwise.  In the real world, variable
> values may move around in and from RAM to CPU registers and back while
> being identified as a single consistent entity.  This helps to
> illustrate the difference between a language and its implementation.

So a char object is really a pointer to char, an int object is
really a pointer to int, and a char** object is really a char**?

I think you're simply adding an extra -- and unnecessary -- level
of indirection, and of confusion.

There may also be some confusion between pointer *objects* and
pointer *values* (i.e., addresses).

If I define an object of struct type and perform some operation
on it (say, a simple assignment), the generated code might very
well refer to the address of the object.  There is no *object*
of pointer type, either explicitly or implicitly.

Struct objects are very often manipulated via pointers (simulating
by-reference argument passing, for example), but that's a coding
convention, not anything inherent to the language.

A struct object is a struct object, just as a scalar object is a
scalar object.  The distinction you see between structs and scalars
doesn't exist.  (Certainly there's a distinction, but it's not the
one you're talking about.)

>> In C terms, 'a' names an object and 'a' is a (modifiable) lvalue
>> expression, just as if it had been declared to be an int.  trying to
>> reconcile this with some model that says it's a pointer (when it isn't
>> one) is bound to be confusing.
>
> I was never happy with the term lvalue or rvalue.  My brain wants to
> think in terms of pointers, variables, and values.  Structures defined
> as automatic variables don't fit all that neatly in that classification.

C's definitions of the terms lvalue and rvalue is not consistent with
their original meanings.

Originally, an expression could be evaluated in two different ways,
depending on the context in which it appears.  Given an assignment:

    int x = 42;
    int y;
    y = x;

The expression `x` (on the right side of the assignment, thus
"rvalue") is evaluated *for its rvalue*, which is 42, whereas
the expresison `y` (on the left side, thus "lvalue" is evaluated
*for its lvalue*, which is the identify of the object named "y",
regardless of what value it happens to contain.  (Either can be a
more complex expression, for example `arr[func(42)].member = abs(x)
+ 42;`, so there can be some non-trivial computation involved in
determining an lvalue.)

The C standard changed the meaning of "lvalue", so it refers to the
expression `y` itself, rather than to the result of evaluating it.
The standard doesn't use the term "rvalue" other than in a footnote,
which mentions in passing that an rvalue is the result of an
expression.

See N1337 6.3.2.1.

To oversimplify, an lvalue in C is an expression that designates
an object.  Note carefully that *designating* an object needn't
involve generating a *pointer* to an object, or equivalently
computing the address of an object.  A simple example:

    int x = 42;
    register int y;
    y = x;

`y` is an lvalue, but it refers to an object that has no address.
The same thing happens if `y` is a bit field.

Dropping the "register" keyword doesn't make any real conceptual
difference -- nor does making `x` and `y` structures rather than
scalars.

You're right: "Structures defined as automatic variables don't fit
all that neatly in that classification" (of pointers, variables,
and values).  The problem is not with the language, it's with your
way of thinking about it.

-- 
Keith Thompson (The_Other_Keith) kst-u@mib.org  <http://www.ghoti.net/~kst>
    Will write code for food.
"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


Thread

Compatibility question Steve Thompson <stevet810@gmail.com> - 2012-10-20 03:08 +0000
  Re: Compatibility question Ian Collins <ian-news@hotmail.com> - 2012-10-20 16:20 +1300
    Re: Compatibility question Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-10-20 11:50 +0100
      Re: Compatibility question Keith Thompson <kst-u@mib.org> - 2012-10-20 11:41 -0700
        Re: Compatibility question Steve Thompson <stevet810@gmail.com> - 2012-10-21 23:04 +0000
          Re: Compatibility question Barry Schwarz <schwarzb@dqel.com> - 2012-10-21 20:27 -0700
    Re: Compatibility question Steve Thompson <stevet810@gmail.com> - 2012-10-20 04:01 +0000
      Re: Compatibility question Ian Collins <ian-news@hotmail.com> - 2012-10-21 09:26 +1300
        Re: Compatibility question Steve Thompson <stevet810@gmail.com> - 2012-10-21 22:54 +0000
          Re: Compatibility question Ian Collins <ian-news@hotmail.com> - 2012-10-22 12:29 +1300
            Re: Compatibility question Steve Thompson <stevet810@gmail.com> - 2012-10-21 23:50 +0000
              Re: Compatibility question Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-10-22 02:27 +0100
                Re: Compatibility question Steve Thompson <stevet810@gmail.com> - 2012-10-22 02:28 +0000
                Re: Compatibility question Eric Sosman <esosman@comcast-dot-net.invalid> - 2012-10-22 11:18 -0400
                Re: Compatibility question Steve Thompson <stevet810@gmail.com> - 2012-10-22 16:19 +0000
                Re: Compatibility question Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-10-22 17:37 +0100
                Re: Compatibility question Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-10-22 17:40 +0100
                Re: Compatibility question Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-10-22 17:30 +0100
                Re: Compatibility question Steve Thompson <stevet810@gmail.com> - 2012-10-22 17:23 +0000
                Re: Compatibility question Keith Thompson <kst-u@mib.org> - 2012-10-22 10:52 -0700
                Re: Compatibility question Steve Thompson <stevet810@gmail.com> - 2012-10-22 18:42 +0000
                Re: Compatibility question Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-10-22 21:06 +0100
                Re: Compatibility question Steve Thompson <stevet810@gmail.com> - 2012-10-22 22:52 +0000
                Re: Compatibility question Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-10-23 03:33 +0100
                Re: Compatibility question Steve Thompson <stevet810@gmail.com> - 2012-10-23 12:28 +0000
                Re: Compatibility question "BartC" <bc@freeuk.com> - 2012-10-23 16:45 +0100
                Re: Compatibility question Steve Thompson <stevet810@gmail.com> - 2012-10-23 17:53 +0000
                Re: Compatibility question Keith Thompson <kst-u@mib.org> - 2012-10-23 12:41 -0700
                Re: Compatibility question "BartC" <bc@freeuk.com> - 2012-10-23 21:28 +0100
                Re: Compatibility question Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-10-23 20:57 +0100
                Re: Compatibility question Keith Thompson <kst-u@mib.org> - 2012-10-23 12:26 -0700
                Re: Compatibility question Steve Thompson <stevet810@gmail.com> - 2012-10-23 20:39 +0000
                Re: Compatibility question Keith Thompson <kst-u@mib.org> - 2012-10-23 15:53 -0700
                Re: Compatibility question "BartC" <bc@freeuk.com> - 2012-10-24 00:57 +0100
                Re: Compatibility question Keith Thompson <kst-u@mib.org> - 2012-10-23 20:06 -0700
                Re: Compatibility question "BartC" <bc@freeuk.com> - 2012-10-24 11:18 +0100
                Re: Compatibility question Keith Thompson <kst-u@mib.org> - 2012-10-24 12:04 -0700
                Re: Compatibility question "BartC" <bc@freeuk.com> - 2012-10-24 23:10 +0100
                Re: Compatibility question Keith Thompson <kst-u@mib.org> - 2012-10-24 16:58 -0700
                Re: Compatibility question "BartC" <bc@freeuk.com> - 2012-10-25 01:46 +0100
                Re: Compatibility question Keith Thompson <kst-u@mib.org> - 2012-10-24 19:40 -0700
                Re: Compatibility question Steve Thompson <stevet810@gmail.com> - 2012-10-24 20:20 +0000
                Re: Compatibility question Keith Thompson <kst-u@mib.org> - 2012-10-24 14:38 -0700
                Re: Compatibility question James Kuyper <jameskuyper@verizon.net> - 2012-10-24 17:55 -0400
                Re: Compatibility question Keith Thompson <kst-u@mib.org> - 2012-10-24 16:29 -0700
                Re: Compatibility question Greg Martin <greg@softsprocket.com> - 2012-10-24 15:21 -0700
                Re: Compatibility question Steve Thompson <stevet810@gmail.com> - 2012-10-26 03:30 +0000
                Re: Compatibility question Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-10-26 13:02 +0100
                Re: Compatibility question Steve Thompson <stevet810@gmail.com> - 2012-10-27 00:04 +0000
                Re: Compatibility question Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-10-27 20:15 +0100
                Re: Compatibility question Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2012-10-27 16:36 -0600
                Re: Compatibility question Steve Thompson <stevet810@gmail.com> - 2012-10-28 17:36 +0000
                Re: Compatibility question Phil Carmody <thefatphil_demunged@yahoo.co.uk> - 2012-10-27 22:42 +0300
                Re: Compatibility question Greg Martin <greg@softsprocket.com> - 2012-10-27 14:30 -0700
                Re: Compatibility question "BartC" <bc@freeuk.com> - 2012-10-27 22:57 +0100
                Re: Compatibility question Keith Thompson <kst-u@mib.org> - 2012-10-27 17:04 -0700
                Re: Compatibility question Keith Thompson <kst-u@mib.org> - 2012-10-27 17:14 -0700
                Re: Compatibility question Keith Thompson <kst-u@mib.org> - 2012-10-27 18:04 -0700
                Re: Compatibility question Keith Thompson <kst-u@mib.org> - 2012-10-24 16:46 -0700
                Re: Compatibility question Steve Thompson <stevet810@gmail.com> - 2012-10-25 01:18 +0000
                Re: Compatibility question Phil Carmody <thefatphil_demunged@yahoo.co.uk> - 2012-10-27 21:08 +0300
                Re: Compatibility question Steve Thompson <stevet810@gmail.com> - 2012-10-28 17:38 +0000
                Re: Compatibility question "BartC" <bc@freeuk.com> - 2012-10-23 00:38 +0100
                Re: Compatibility question Keith Thompson <kst-u@mib.org> - 2012-10-22 16:50 -0700
                Re: Compatibility question Steve Thompson <stevet810@gmail.com> - 2012-10-23 12:33 +0000
                Re: Compatibility question Öö Tiib <ootiib@hot.ee> - 2012-10-22 14:23 -0700
                Re: Compatibility question James Kuyper <jameskuyper@verizon.net> - 2012-10-22 17:26 -0400
                Re: Compatibility question Ian Collins <ian-news@hotmail.com> - 2012-10-23 10:55 +1300
                Re: Compatibility question Steve Thompson <stevet810@gmail.com> - 2012-10-22 23:27 +0000
                Re: Compatibility question "BartC" <bc@freeuk.com> - 2012-10-22 22:44 +0100
                Re: Compatibility question Les Cargill <lcargill99@comcast.com> - 2012-10-22 17:15 -0500
                Re: Compatibility question "BartC" <bc@freeuk.com> - 2012-10-23 00:13 +0100
                Re: Compatibility question James Kuyper <jameskuyper@verizon.net> - 2012-10-22 18:35 -0400
                Re: Compatibility question "BartC" <bc@freeuk.com> - 2012-10-23 00:14 +0100
                Re: Compatibility question Steve Thompson <stevet810@gmail.com> - 2012-10-22 23:42 +0000
                Re: Compatibility question Ian Collins <ian-news@hotmail.com> - 2012-10-23 13:35 +1300
                Re: Compatibility question Keith Thompson <kst-u@mib.org> - 2012-10-22 17:01 -0700
                Re: Compatibility question "BartC" <bc@freeuk.com> - 2012-10-23 01:47 +0100
              Re: Compatibility question Keith Thompson <kst-u@mib.org> - 2012-10-21 19:27 -0700

csiph-web