Topic: ostream::operator<<(const? void*)
Author: presto@haggard.gg.caltech.edu (Preston Pfarner)
Date: 1997/04/11 Raw View
In article <199704091803.LAA03053@taumet.eng.sun.com>
Stephen.Clamage@Eng.Sun.COM (Steve Clamage) writes:
[ ... historical situation snipped ... ]
> We expect to change the parameter to to "const void*", since there
> is a need for that signature, but there doesn't seem to be a need for
> the non-const version.
Good. Not only is there no need for the non-const version (that I can
see), its existence would imply that printing out a pointer value could
conceivably change the contents of the pointed-at object.
If this will be changed, then my concerns disappear as it's easy to
define a workaround for the interim. The current situation was rather
annoying to track down, though, as const void* objects were implicitly
cast to bool before printing.
ostream& operator<<(ostream& os, const void* p) {
return os << const_cast<void*>(p);
}
--
Preston Pfarner
mailto:presto@gg.caltech.edu
http://www.gg.caltech.edu/~presto/
---
[ comp.std.c++ is moderated. To submit articles: Try just posting with your
newsreader. If that fails, use mailto:std-c++@ncar.ucar.edu
comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
Comments? mailto:std-c++-request@ncar.ucar.edu
]
Author: Michael R Cook <michael_cook%erawan@cognex.com>
Date: 1997/04/10 Raw View
>>>>> "SC" == Steve Clamage <Stephen.Clamage@Eng.Sun.COM> writes:
SC> In article fsf@shaggy.gg.caltech.edu, presto@shaggy.gg.caltech.edu (Preston Pfarner) writes:
>> ostream::operator<<(void*) // defined in DWP.
SC> We expect to change the parameter to to "const void*", since there is a
SC> need for that signature, but there doesn't seem to be a need for the
SC> non-const version.
Shouldn't it be `volatile const void*'? How come const seems to get all the
proper attention, and volatile is almost always ignored?
---
[ comp.std.c++ is moderated. To submit articles: Try just posting with your
newsreader. If that fails, use mailto:std-c++@ncar.ucar.edu
comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
Comments? mailto:std-c++-request@ncar.ucar.edu
]
Author: presto@shaggy.gg.caltech.edu (Preston Pfarner)
Date: 1997/04/08 Raw View
I've found what appears to be a general ostream problem. I expected
this to be a FAQ given its relevance, but could see no mention.
Here's some code, as found in both the DWP and my compiler's headers:
ostream::operator<<(void*) // defined in DWP.
ostream::operator<<(const void*) // not mentioned in DWP.
So if I have a pointer-to-const, I can't print out its value without
using a const_cast. Also, there's no good reason why void* should
be printable and const void* not unless the act of printing could
change the object addressed by the pointer. This seems quite wrong.
Looking at the AT&T iostream.h (as found in recent HP and SGI
distributions) there is a commented declaration of the const void*
version with a note "add this later". Does this indicate that there
was some expectation that there would be a change?
Does anyone know any good reasons why the current state is
better than just defining ostream::operator<<(const void*)?
If not, we should change this in the working paper.
Similar comments apply for istream::operator>>(void*&).
--
Preston Pfarner
mailto:presto@gg.caltech.edu
http://www.gg.caltech.edu/~presto/
---
[ comp.std.c++ is moderated. To submit articles: Try just posting with your
newsreader. If that fails, use mailto:std-c++@ncar.ucar.edu
comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
Comments? mailto:std-c++-request@ncar.ucar.edu
]
Author: Stephen.Clamage@Eng.Sun.COM (Steve Clamage)
Date: 1997/04/09 Raw View
In article fsf@shaggy.gg.caltech.edu, presto@shaggy.gg.caltech.edu (Preston Pfarner) writes:
>I've found what appears to be a general ostream problem. I expected
>this to be a FAQ given its relevance, but could see no mention.
>Here's some code, as found in both the DWP and my compiler's headers:
>
> ostream::operator<<(void*) // defined in DWP.
> ostream::operator<<(const void*) // not mentioned in DWP.
>
>So if I have a pointer-to-const, I can't print out its value without
>using a const_cast.
This deficiency dates back to original iostreams (as you noted in the
original article), and should have long since been fixed. Several of
us on the committee thought it was fixed years ago, but if it was,
it somehow got unfixed again. We expect to change the parameter to
to "const void*", since there is a need for that signature, but there
doesn't seem to be a need for the non-const version.
---
Steve Clamage, stephen.clamage@eng.sun.com
---
[ comp.std.c++ is moderated. To submit articles: Try just posting with your
newsreader. If that fails, use mailto:std-c++@ncar.ucar.edu
comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
Comments? mailto:std-c++-request@ncar.ucar.edu
]