C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Voided application of indirection operator to pointer-to-voi

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language, library and standards
View previous topic :: View next topic  
Author Message
Al Grant
Guest





PostPosted: Mon Jul 21, 2003 3:06 pm    Post subject: Voided application of indirection operator to pointer-to-voi Reply with quote



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 ]

Back to top
Andrew Koenig
Guest





PostPosted: Mon Jul 21, 2003 4:14 pm    Post subject: Re: Voided application of indirection operator to pointer-to Reply with quote



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, [email]ark (AT) acm (DOT) org[/email]

---
[ 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 ]

Back to top
Ben Hutchings
Guest





PostPosted: Mon Jul 21, 2003 6:33 pm    Post subject: Re: Voided application of indirection operator to pointer-to Reply with quote



In article <5765b025.0307210232.6c571eff (AT) posting (DOT) google.com>, Al Grant wrote:
Quote:
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).

Quote:
and 5.3.1 indicates that those generated by the indirection operator
must have an object type.

Or function type.

Quote:
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 ]


Back to top
Gabriel Dos Reis
Guest





PostPosted: Mon Jul 21, 2003 7:08 pm    Post subject: Re: Voided application of indirection operator to pointer-to Reply with quote

[email]do-not-spam-benh (AT) bwsint (DOT) com[/email] (Ben Hutchings) writes:

Quote:
(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, [email]gdr (AT) integrable-solutions (DOT) net[/email]

---
[ 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 ]


Back to top
Francis Glassborow
Guest





PostPosted: Tue Jul 22, 2003 2:01 am    Post subject: Re: Voided application of indirection operator to pointer-to Reply with quote

In article <m3smozpw0n.fsf (AT) uniton (DOT) integrable-solutions.net>, Gabriel Dos
Reis <gdr (AT) integrable-solutions (DOT) net> writes
Quote:
do-not-spam-benh (AT) bwsint (DOT) 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 ]


Back to top
Al Grant
Guest





PostPosted: Tue Jul 22, 2003 6:46 pm    Post subject: Re: Voided application of indirection operator to pointer-to Reply with quote

[email]do-not-spam-benh (AT) bwsint (DOT) com[/email] (Ben Hutchings) wrote in message news:<slrnbho5vh.18k.do-not-spam-benh (AT) tin (DOT) bwsint.com>...
Quote:
In article <5765b025.0307210232.6c571eff (AT) posting (DOT) 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.

Quote:
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 ]


Back to top
Ron Natalie
Guest





PostPosted: Tue Jul 22, 2003 6:47 pm    Post subject: Re: Voided application of indirection operator to pointer-to Reply with quote


"Francis Glassborow" <francis (AT) robinton (DOT) demon.co.uk> wrote

Quote:
In article <m3smozpw0n.fsf (AT) uniton (DOT) integrable-solutions.net>, Gabriel Dos
Reis <gdr (AT) integrable-solutions (DOT) net> writes
[email]do-not-spam-benh (AT) bwsint (DOT) com[/email] (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 ]


Back to top
Al Grant
Guest





PostPosted: Tue Jul 22, 2003 10:57 pm    Post subject: Re: Voided application of indirection operator to pointer-to Reply with quote

[email]francis (AT) robinton (DOT) demon.co.uk[/email] (Francis Glassborow) wrote in message news:<nHKM1wVXzGH$Ew4O (AT) robinton (DOT) demon.co.uk>...
Quote:
In article <m3smozpw0n.fsf (AT) uniton (DOT) integrable-solutions.net>, Gabriel Dos
Reis <gdr (AT) integrable-solutions (DOT) 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 ]


Back to top
Ben Hutchings
Guest





PostPosted: Wed Jul 23, 2003 1:30 am    Post subject: Re: Voided application of indirection operator to pointer-to Reply with quote

In article <m3smozpw0n.fsf (AT) uniton (DOT) integrable-solutions.net>,
Gabriel Dos Reis wrote:
Quote:
do-not-spam-benh (AT) bwsint (DOT) 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 ]


Back to top
Francis Glassborow
Guest





PostPosted: Wed Jul 23, 2003 3:08 pm    Post subject: Re: Voided application of indirection operator to pointer-to Reply with quote

In article <5765b025.0307220523.533d214a (AT) posting (DOT) google.com>, Al Grant
<algrant (AT) myrealbox (DOT) com> writes
Quote:
francis (AT) robinton (DOT) demon.co.uk (Francis Glassborow) wrote in message news:<nHKM1wVXzGH$Ew4O (AT) robinton (DOT) demon.co.uk>...
In article <m3smozpw0n.fsf (AT) uniton (DOT) integrable-solutions.net>, Gabriel Dos
Reis <gdr (AT) integrable-solutions (DOT) 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 ]


Back to top
Gabriel Dos Reis
Guest





PostPosted: Wed Jul 23, 2003 7:01 pm    Post subject: Re: Voided application of indirection operator to pointer-to Reply with quote

[email]algrant (AT) myrealbox (DOT) com[/email] (Al Grant) writes:

Quote:
francis (AT) robinton (DOT) demon.co.uk (Francis Glassborow) wrote in message news:<nHKM1wVXzGH$Ew4O (AT) robinton (DOT) demon.co.uk>...
In article <m3smozpw0n.fsf (AT) uniton (DOT) integrable-solutions.net>, Gabriel Dos
Reis <gdr (AT) integrable-solutions (DOT) 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.

Quote:
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, [email]gdr (AT) integrable-solutions (DOT) net[/email]

---
[ 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 ]


Back to top
Gabriel Dos Reis
Guest





PostPosted: Thu Jul 24, 2003 2:11 am    Post subject: Re: Voided application of indirection operator to pointer-to Reply with quote

[email]francis (AT) robinton (DOT) demon.co.uk[/email] (Francis Glassborow) writes:

Quote:
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.

Quote:
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, [email]gdr (AT) integrable-solutions (DOT) net[/email]

---
[ 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 ]


Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language, library and standards All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.