Topic: Is overriding a function of a library in accordance with C++
Author: Jens Theisen <jth02@arcor.de>
Date: Fri, 25 Aug 2006 14:46:59 CST Raw View
Lighter wrote:
> Is overriding a function of a library in accordance with C++ standard?
As people in comp.lang.c++ already told you a couple of hours ago,
you're hiding a function name with a name in a different namespace.
But why are you asking this question unmodified again here?
Jens
---
[ 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.comeaucomputing.com/csc/faq.html ]
Author: jth02@arcor.de (Jens Theisen)
Date: Sun, 27 Aug 2006 22:14:21 GMT Raw View
kuyper@wizard.net wrote:
> I'm not sure I follow that. How could a question about whether the C++
> standard allows something not be on-topic for comp.std.c++?
Because it's really a question like "why does my code not work as I
expect it", just with a "does the standard allow it" on top of it. It's
clearly not a question where you need expert C++ standard knowledge for.
As I said in the other posting, this guy already asked this question in
comp.lang.c++ and was helped there properly - before he posted it here.
Jens
---
[ 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.comeaucomputing.com/csc/faq.html ]
Author: Steve Clamage <stephen.clamage@sun.com>
Date: Fri, 25 Aug 2006 10:37:36 CST Raw View
Lighter wrote:
> Is overriding a function of a library in accordance with C++ standard?
In the C++ Standard, Section 17.4 (taking about 8 pages) describes in detail
what is allowed and what is not allowed.
Very briefly: You can override the new and delete functions and the default
handler functions from the Standard Library, but the overriding functions must
meet the requirements listed in the Standard. Doing anything else (including
overriding other Standard Library functions) has undefined behavior.
"Undefined behavior" means that the Standard places no requirements on the C++
implementation, and that the programmer cannot depend on any particular result.
A compiler might refuse to compile the code (thus making it impossible to build
the standard library or a replacement for it), or issue a warning, or quietly
accept the code.
The link-time environment might be such that actual overriding is impossible, or
that overriding would be inconsistent (the real library function used in some
parts of the program), or that overriding actually occurs everwhere.
If you think a compiler should warn about code like your example (replacing
strlen), you could ask your vendor.
Speaking as a compiler implementor, I would not be very interested in supplying
such a warning. It would affect compiler performance, since every declaration in
the global and std namespaces would have to be checked against the list of
library functions. In addition, the warning would have to be disabled for inline
functions defined in the standard headers. It's a lot of trouble for what seems
(to me) like a minor issue.
---
Steve Clamage
Sun Microsystems
---
[ 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.comeaucomputing.com/csc/faq.html ]