W
William L. Bahn
===========
(N869, p8) An object is a region of data storage in the execution
environment, the contents of which can represent values.
When explaining this to students, is it reasonable to say
something like:
From a practical standpoint, objects are things that have
addresses - addresses that can be computed. This doesn't
necessarily mean that we can both read and write to that object -
we may be able to do one, the other, or both (if we can't do
either, it's rather pointless).
So a string literal is an object. It is sitting in memory when
your program is running. We can determine the address of it. We
can read from it. We shouldn't write to it (doing so invokes
undefined behavior).
But a numerical constant, such as the 3 in
y = x + 3;
is not an object. It is not (at least not guaranteed to be) at a
particular region of data storage. It is very possibly a value
embedded in an instruction's op code. Trying to compute the
address of 3 will invoke undefined behavior.
That last clause, about "the contents of which can represent
values". Is that basically rhetorical or it is important to the
definition of an object. Asked another way, what would be
incorrect about just saying that an object is a region of data
storage in the execution environment? What things (worthy of
making the distinction) would that include that would not be
included as objects under the actual definition?
===========
(N869, p68 - subclause 6.5) An expression is a sequence of
operators and operands that specifies computation of a value, or
that designates an object or a function, or that generates side
effects, or that performs a combination thereof.
So what about just a constant?
The line:
32;
Does nothing, but it's a legal expression, right? Yet is it not
an operand (since there is not operator), it is not an operator,
it denotes neither an object nor a function, and it generates no
side effects. So, technically, this isn't an expression, correct?
But the next subclause, 6.5.1, specifically says that an
identifier (provided it denotes an object or a function), a
constant, a string literal (which denotes an object), and a
parenthesized expression are all primary expressions. This is in
agreement with the basic definition of an expression except for
the case of a constant.
Is this a subtle oversight in the basic definition of an
expression? Or am I just not reading something right?
(N869, p8) An object is a region of data storage in the execution
environment, the contents of which can represent values.
When explaining this to students, is it reasonable to say
something like:
From a practical standpoint, objects are things that have
addresses - addresses that can be computed. This doesn't
necessarily mean that we can both read and write to that object -
we may be able to do one, the other, or both (if we can't do
either, it's rather pointless).
So a string literal is an object. It is sitting in memory when
your program is running. We can determine the address of it. We
can read from it. We shouldn't write to it (doing so invokes
undefined behavior).
But a numerical constant, such as the 3 in
y = x + 3;
is not an object. It is not (at least not guaranteed to be) at a
particular region of data storage. It is very possibly a value
embedded in an instruction's op code. Trying to compute the
address of 3 will invoke undefined behavior.
That last clause, about "the contents of which can represent
values". Is that basically rhetorical or it is important to the
definition of an object. Asked another way, what would be
incorrect about just saying that an object is a region of data
storage in the execution environment? What things (worthy of
making the distinction) would that include that would not be
included as objects under the actual definition?
===========
(N869, p68 - subclause 6.5) An expression is a sequence of
operators and operands that specifies computation of a value, or
that designates an object or a function, or that generates side
effects, or that performs a combination thereof.
So what about just a constant?
The line:
32;
Does nothing, but it's a legal expression, right? Yet is it not
an operand (since there is not operator), it is not an operator,
it denotes neither an object nor a function, and it generates no
side effects. So, technically, this isn't an expression, correct?
But the next subclause, 6.5.1, specifically says that an
identifier (provided it denotes an object or a function), a
constant, a string literal (which denotes an object), and a
parenthesized expression are all primary expressions. This is in
agreement with the basic definition of an expression except for
the case of a constant.
Is this a subtle oversight in the basic definition of an
expression? Or am I just not reading something right?