Topic: Equality comparison of const and volatile pointers
Author: GryMor <metke@cc.wwu.edu>
Date: 1999/09/02 Raw View
//Hello, I'm wondering if the following code should result in 0 exit
//status (at least acording to the standerd) My compiler is choking on
//the equality.
int main(void)
{
char * a = new char[2];
const char * ca = a;
volatile char * va = a;
return !(ca==va);
}
[ 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://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: Francis Glassborow <francis@robinton.demon.co.uk>
Date: 1999/09/03 Raw View
In article <Pine.SOL.4.05.9909021353020.101-100000@titan.cc.wwu.edu>,
GryMor <metke@cc.wwu.edu> writes
>//Hello, I'm wondering if the following code should result in 0 exit
>//status (at least acording to the standerd) My compiler is choking on
>//the equality.
>
>int main(void)
>{
> char * a = new char[2];
> const char * ca = a;
> volatile char * va = a;
> return !(ca==va);
>}
IIRC one of the requirements for pointer comparison is that they are of
compatible types. I am not sure that this includes converting both ca
and vac to char volatile const * type. Added to which I would welcome a
compiler that warned you that you have never released the dynamic
resources held by a.
Francis Glassborow Journal Editor, Association of C & C++ Users
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://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: wmm@fastdial.net
Date: 1999/09/03 Raw View
In article <Pine.SOL.4.05.9909021353020.101-100000@titan.cc.wwu.edu>,
GryMor <metke@cc.wwu.edu> wrote:
>
> //Hello, I'm wondering if the following code should result in 0 exit
> //status (at least acording to the standerd) My compiler is choking on
> //the equality.
>
> int main(void)
> {
> char * a = new char[2];
> const char * ca = a;
> volatile char * va = a;
> return !(ca==va);
> }
The comparison is well-formed according to the Standard: in a
pointer comparison, the pointers are converted to a "composite
pointer type," in which the cv-qualification (const and/or volatile)
is the union of the cv-qualifications of the two operands (5.9p2).
--
William M. Miller, wmm@fastdial.net
Software Emancipation Technology (www.setech.com)
Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
[ 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://reality.sgi.com/austern_mti/std-c++/faq.html ]