Topic: Voided application of indirection operator to pointer-to-void
Author: gdr@integrable-solutions.net (Gabriel Dos Reis)
Date: Wed, 23 Jul 2003 19:01:17 +0000 (UTC) Raw View
algrant@myrealbox.com (Al Grant) writes:
| francis@robinton.demon.co.uk (Francis Glassborow) wrote in message news:<nHKM1wVXzGH$Ew4O@robinton.demon.co.uk>...
| > In article <m3smozpw0n.fsf@uniton.integrable-solutions.net>, Gabriel Dos
| > Reis <gdr@integrable-solutions.net> writes
| > >C does not have "rvalue". It, however, has the notion of 'lvalue'.
| >
| > Well PJ Plauger has multiple references to rvalue in the book he
| > co-authored with Jim Brodie (ANSI and ISO Standard C Programmer's
| > Reference)so I find that assertion untenable.
|
| The only reference to 'rvalue' in Standard C is to a footnote:
|
| What is sometimes called "rvalue" is in this International
| Standard described as the "value of an expression".
Right. And the normative part of the definition of standard C never
uses, never defines what an rvalue may mean in C.
| AFAICT this is true of every version of Standard C dating back
| to old ANSI drafts, except it didn't say "International" then.
yeah.
--
Gabriel Dos Reis, gdr@integrable-solutions.net
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: gdr@integrable-solutions.net (Gabriel Dos Reis)
Date: Thu, 24 Jul 2003 02:11:53 +0000 (UTC) Raw View
francis@robinton.demon.co.uk (Francis Glassborow) writes:
| So the term is not used in the Standard but the concept is and the
| footnote makes it clear that the concept used is equivalent to rvalue.
except that the normative text definitions of "value" and "expression"
do not really combine to make sense of the "sloppy" wording in the
non-normative text.
| IOWs C does have rvalues, it just chose not to call them that in the
| Standard.
Please have a closer look at C++ definition of rvalue and what the
non-normative text in the C standard.
The C committee chooses not to use a fuzzy word probably for good reasons.
--
Gabriel Dos Reis, gdr@integrable-solutions.net
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: do-not-spam-benh@bwsint.com (Ben Hutchings)
Date: Mon, 21 Jul 2003 18:33:57 +0000 (UTC) Raw View
In article <5765b025.0307210232.6c571eff@posting.google.com>, Al Grant wrote:
> Is this legal C++?
>
> void f(void *pv) { *pv; }
>
> Comeau and g++ both fault it. 5.3.1 says the operand of * must be T*
> where T is an object type or function type - so not void.
<snip>
> However, we have another source claiming the code is legal, citing 4.1
> as showing an intention to allow (undereferenced) lvalues of incomplete
> type and deducing that if 5.3.1 forbids this it is an oversight.
>
> It seems to me that 4.1 only implies that lvalues of some incomplete
> types may exist,
You are quite right. There are no lvalues of void type (3.10p2).
> and 5.3.1 indicates that those generated by the indirection operator
> must have an object type.
Or function type.
> I can believe that the committee might have intended to allow creation
> of void lvalues, motivated either by orthogonality, or by compatibility
> with C.
<snip>
I very much doubt it; I can't see that it would be meaningful to have a
void lvalue, and I don't believe C allows it either. (void rvalues do
exist in both C and C++, though.)
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: gdr@integrable-solutions.net (Gabriel Dos Reis)
Date: Mon, 21 Jul 2003 19:08:01 +0000 (UTC) Raw View
do-not-spam-benh@bwsint.com (Ben Hutchings) writes:
| (void rvalues do
| exist in both C and C++, though.)
C does not have "rvalue". It, however, has the notion of 'lvalue'.
--
Gabriel Dos Reis, gdr@integrable-solutions.net
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: francis@robinton.demon.co.uk (Francis Glassborow)
Date: Tue, 22 Jul 2003 02:01:29 +0000 (UTC) Raw View
In article <m3smozpw0n.fsf@uniton.integrable-solutions.net>, Gabriel Dos
Reis <gdr@integrable-solutions.net> writes
>do-not-spam-benh@bwsint.com (Ben Hutchings) writes:
>
>> (void rvalues do
>> exist in both C and C++, though.)
>
>C does not have "rvalue". It, however, has the notion of 'lvalue'.
Well PJ Plauger has multiple references to rvalue in the book he
co-authored with Jim Brodie (ANSI and ISO Standard C Programmer's
Reference)so I find that assertion untenable.
--
Francis Glassborow ACCU
64 Southfield Rd
Oxford OX4 1PA +44(0)1865 246490
All opinions are mine and do not represent those of any organisation
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: algrant@myrealbox.com (Al Grant)
Date: Tue, 22 Jul 2003 18:46:45 +0000 (UTC) Raw View
do-not-spam-benh@bwsint.com (Ben Hutchings) wrote in message news:<slrnbho5vh.18k.do-not-spam-benh@tin.bwsint.com>...
> In article <5765b025.0307210232.6c571eff@posting.google.com>, Al Grant wrote:
> > and 5.3.1 indicates that those generated by the indirection operator
> > must have an object type.
>
> Or function type.
Ok, I was forgetting that in C++ function designators are still lvalues.
> > I can believe that the committee might have intended to allow creation
> > of void lvalues, motivated either by orthogonality, or by compatibility
> > with C.
> <snip>
>
> I very much doubt it; I can't see that it would be meaningful to have a
> void lvalue, and I don't believe C allows it either.
But that's the wrong question. The question is whether it allows
application of the indirection operator to a pointer-to-void, with
a well defined result, whether or not that result is an lvalue.
Reading 6.5.3.2 suggests this is in fact the case, and the result
is not an lvalue: note the description of the operand of the
unary & operator:
"either a function designator, the result of a [] or unary *
operator, or an lvalue that designates an object that is not
a bit-field and is not declared with the register storage-class
specifier."
Now this is curious wording if the result of unary * is always
an lvalue/FD. So it presumably is not. Reading further in 6.5.3.2
and footnote 83 suggests that the result of *pv is simply a
denotation of indirection - and that &*pv is well-defined and equal
to pv, which implies that *pv is well-defined, though of limited
usefulness. In particular, not being an lvalue, it is not subject
to the usual void-context (in C) lvalue-to-rvalue conversion.
There appears to be nothing to make it illegal.
Note that the description of unary & is more extensive than in
C89. In C89 the case of &*pv was considered in DR#12 (and ruled
illegal) and the case of (void)*pv was considered in DR#106 (and
ruled legal). DR 106 should be sufficient evidence that C++
introduced a compatibility issue for the original code example.
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: ron@sensor.com ("Ron Natalie")
Date: Tue, 22 Jul 2003 18:47:15 +0000 (UTC) Raw View
"Francis Glassborow" <francis@robinton.demon.co.uk> wrote in message news:nHKM1wVXzGH$Ew4O@robinton.demon.co.uk...
> In article <m3smozpw0n.fsf@uniton.integrable-solutions.net>, Gabriel Dos
> Reis <gdr@integrable-solutions.net> writes
> >do-not-spam-benh@bwsint.com (Ben Hutchings) writes:
> >
> >> (void rvalues do
> >> exist in both C and C++, though.)
> >
> >C does not have "rvalue". It, however, has the notion of 'lvalue'.
>
> Well PJ Plauger has multiple references to rvalue in the book he
> co-authored with Jim Brodie (ANSI and ISO Standard C Programmer's
> Reference)so I find that assertion untenable.
The C standard doesn't ever use rvalue. Things are either lvalues or
not. C lvalues can be used in expressions directly where C++ requires
an lvalue-to-rvalue conversion.
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: algrant@myrealbox.com (Al Grant)
Date: Tue, 22 Jul 2003 22:57:44 +0000 (UTC) Raw View
francis@robinton.demon.co.uk (Francis Glassborow) wrote in message news:<nHKM1wVXzGH$Ew4O@robinton.demon.co.uk>...
> In article <m3smozpw0n.fsf@uniton.integrable-solutions.net>, Gabriel Dos
> Reis <gdr@integrable-solutions.net> writes
> >C does not have "rvalue". It, however, has the notion of 'lvalue'.
>
> Well PJ Plauger has multiple references to rvalue in the book he
> co-authored with Jim Brodie (ANSI and ISO Standard C Programmer's
> Reference)so I find that assertion untenable.
The only reference to 'rvalue' in Standard C is to a footnote:
What is sometimes called "rvalue" is in this International
Standard described as the "value of an expression".
AFAICT this is true of every version of Standard C dating back
to old ANSI drafts, except it didn't say "International" then.
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: do-not-spam-benh@bwsint.com (Ben Hutchings)
Date: Wed, 23 Jul 2003 01:30:59 +0000 (UTC) Raw View
In article <m3smozpw0n.fsf@uniton.integrable-solutions.net>,
Gabriel Dos Reis wrote:
> do-not-spam-benh@bwsint.com (Ben Hutchings) writes:
>
>| (void rvalues do
>| exist in both C and C++, though.)
>
> C does not have "rvalue". It, however, has the notion of 'lvalue'.
I know it uses the term "value of an expression", but it also notes that
this is sometimes called "rvalue". I don't think it's helpful to be
picky about slight differences of terminology when comparing C and C++.
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: gdr@integrable-solutions.net (Gabriel Dos Reis)
Date: Wed, 23 Jul 2003 01:32:19 +0000 (UTC) Raw View
francis@robinton.demon.co.uk (Francis Glassborow) writes:
| In article <m3smozpw0n.fsf@uniton.integrable-solutions.net>, Gabriel
| Dos Reis <gdr@integrable-solutions.net> writes
| >do-not-spam-benh@bwsint.com (Ben Hutchings) writes:
| >
| >> (void rvalues do
| >> exist in both C and C++, though.)
| >
| >C does not have "rvalue". It, however, has the notion of 'lvalue'.
|
| Well PJ Plauger has multiple references to rvalue in the book he
| co-authored with Jim Brodie (ANSI and ISO Standard C Programmer's
| Reference)so I find that assertion untenable.
Just check the definition text of standard C.
--
Gabriel Dos Reis, gdr@integrable-solutions.net
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: francis@robinton.demon.co.uk (Francis Glassborow)
Date: Wed, 23 Jul 2003 15:08:02 +0000 (UTC) Raw View
In article <5765b025.0307220523.533d214a@posting.google.com>, Al Grant
<algrant@myrealbox.com> writes
>francis@robinton.demon.co.uk (Francis Glassborow) wrote in message news:<nHKM1wVXzGH$Ew4O@robinton.demon.co.uk>...
>> In article <m3smozpw0n.fsf@uniton.integrable-solutions.net>, Gabriel Dos
>> Reis <gdr@integrable-solutions.net> writes
>> >C does not have "rvalue". It, however, has the notion of 'lvalue'.
>>
>> Well PJ Plauger has multiple references to rvalue in the book he
>> co-authored with Jim Brodie (ANSI and ISO Standard C Programmer's
>> Reference)so I find that assertion untenable.
>
>The only reference to 'rvalue' in Standard C is to a footnote:
>
> What is sometimes called "rvalue" is in this International
> Standard described as the "value of an expression".
>
>AFAICT this is true of every version of Standard C dating back
>to old ANSI drafts, except it didn't say "International" then.
So the term is not used in the Standard but the concept is and the
footnote makes it clear that the concept used is equivalent to rvalue.
IOWs C does have rvalues, it just chose not to call them that in the
Standard.
--
Francis Glassborow ACCU
64 Southfield Rd
Oxford OX4 1PA +44(0)1865 246490
All opinions are mine and do not represent those of any organisation
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: gdr@integrable-solutions.net (Gabriel Dos Reis)
Date: Wed, 23 Jul 2003 15:36:52 +0000 (UTC) Raw View
do-not-spam-benh@bwsint.com (Ben Hutchings) writes:
| In article <m3smozpw0n.fsf@uniton.integrable-solutions.net>,
| Gabriel Dos Reis wrote:
| > do-not-spam-benh@bwsint.com (Ben Hutchings) writes:
| >
| >| (void rvalues do
| >| exist in both C and C++, though.)
| >
| > C does not have "rvalue". It, however, has the notion of 'lvalue'.
|
| I know it uses the term "value of an expression", but it also notes that
| this is sometimes called "rvalue".
notes are not normative. Furthermore, "value of an expression" is
used in a greater generality, and the only places where the C standard
uses the phrase "value of an expression" are:
1) in the non-normative text that is also the only place where the
term "rvalue" appears.
2) 6.5.4/4
[#4] Preceding an expression by a parenthesized type name
converts the value of the expression to the named type.
This construction is called a cast.85) A cast that
specifies no conversion has no effect on the type or value
of an expression.86)
Remember that C has a its own definitions for "value" and "expression"
3.17
[#1] value
precise meaning of the contents of an object when
interpreted as having a specific type
6.5 Expressions
[#1] 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.
| I don't think it's helpful to be
| picky about slight differences of terminology when comparing C and C++.
Well, it is helpful to avoid confusion.
Clearly, C does not define the notion of "rvalue".
C++ does provide a definition for "rvalue" but then the whole thing is
messy, see 3.10:
1 Every expression is either an lvalue or an rvalue.
2 An lvalue refers to an object or function. Some rvalue expressions
those of class or cv-qualified class type also refer to objects.47)
Clearly, there is a semantics shift, and comparing two languages based
on semantics shift is not fair neither helpful.
In short, it helps not to confuse matters by entirely avoiding the
term "rvalue" when talking of C, and even more when talking of C on a
C++ group :-)
My note was meant to be parenthetical, but now I don't know what to
think :-)
--
Gabriel Dos Reis, gdr@integrable-solutions.net
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: algrant@myrealbox.com (Al Grant)
Date: Mon, 21 Jul 2003 15:06:55 +0000 (UTC) Raw View
Is this legal C++?
void f(void *pv) { *pv; }
Comeau and g++ both fault it. 5.3.1 says the operand of * must be T*
where T is an object type or function type - so not void. A note then
says T may be incomplete but that does not contradict the preceding,
as long as it's an incomplete object type. This is motivated by
binding references to objects of incomplete type. The note explicitly
(and redundantly) excludes void.
However, we have another source claiming the code is legal, citing 4.1
as showing an intention to allow (undereferenced) lvalues of incomplete
type and deducing that if 5.3.1 forbids this it is an oversight.
It seems to me that 4.1 only implies that lvalues of some incomplete
types may exist, and 5.3.1 indicates that those generated by the
indirection operator must have an object type. I can believe that
the committee might have intended to allow creation of void lvalues,
motivated either by orthogonality, or by compatibility with C.
But the resulting standard seems neither self-contradictory
nor obviously broken, so it is not clear there is a defect here.
I think this could still benefit from raising a core language issue -
this would be an opportunity to make the construct legal, if that was
the original intention.
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: ark@acm.org (Andrew Koenig)
Date: Mon, 21 Jul 2003 16:14:00 +0000 (UTC) Raw View
Al> Is this legal C++?
Al> void f(void *pv) { *pv; }
No.
Al> Comeau and g++ both fault it. 5.3.1 says the operand of * must be
Al> T* where T is an object type or function type - so not void. A
Al> note then says T may be incomplete but that does not contradict
Al> the preceding, as long as it's an incomplete object type. This is
Al> motivated by binding references to objects of incomplete type.
Al> The note explicitly (and redundantly) excludes void.
Sounds pretty clear, doesn't it?
Al> However, we have another source claiming the code is legal, citing
Al> 4.1 as showing an intention to allow (undereferenced) lvalues of
Al> incomplete type and deducing that if 5.3.1 forbids this it is an
Al> oversight.
I think not.
Al> It seems to me that 4.1 only implies that lvalues of some
Al> incomplete types may exist, and 5.3.1 indicates that those
Al> generated by the indirection operator must have an object type. I
Al> can believe that the committee might have intended to allow
Al> creation of void lvalues, motivated either by orthogonality, or by
Al> compatibility with C. But the resulting standard seems neither
Al> self-contradictory nor obviously broken, so it is not clear there
Al> is a defect here.
Right. Once you complete an incomplete type, you can refer to values
of that type. But void can never be completed.
Al> I think this could still benefit from raising a core language
Al> issue - this would be an opportunity to make the construct legal,
Al> if that was the original intention.
It wasn't.
Why do you want to evaluate *pv anyway if you're not going to use the
result?
--
Andrew Koenig, ark@acm.org
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]