Article View: comp.std.c++
Article #20Re: implicit pointer of pointer argument promotion legal C++?
From: Scott Meyers
Date: Sat, 31 Oct 1992 03:14
Date: Sat, 31 Oct 1992 03:14
42 lines
2101 bytes
2101 bytes
In article <1992Oct30.051334.1016@frumious.uucp> uunet.ca!frumious!pat writes:
| sdm@cs.brown.edu (Scott Meyers) writes:
| |I've been wondering about a similar question. Is there any danger of
| |allowing the "usual" conversions of pointers and references in parameter
| |types of function pointers? Example:
| |
| | void f( int (*)(const void*, const void*) );
| |
| | int g(const char*, const char*);
| |
| | f( g ); // error
| | f (int (*)(const void*, const void*) g ); // fine
| |
| |If the usual T* ==> void* conversion were allowed for function pointer
| |parameters, no cast would be required when calling f with g. Is there a
| |lurking danger here?
|
| I think you have this the wrong way around. The example above is
| dangerous. If f() is
|
| void f( int (*h)(const void*, const void*) ) {
| int x;
| h( &x, &x );
| }
|
| you wind up converting an int* to a void* and then to a const char*.
| Such a conversion should require an explicit cast at some point.
This seems like a program error. The caller is passing a function
expecting const char* arguments, but the callee is using it as if it is
expecting int* parameters. I'm interested in the case where the caller and
the callee agree on the types of what's being passed:
void f( int (*h)(const void*, const void*) ) {
h("Foo", "Bar");
}
Scott
-------------------------------------------------------------------------------
What do you say to a convicted felon in Providence? "Hello, Mr. Mayor."
Technical Details
Message-ID:
<1992Oct31.031431.6863@cs.brown.edu>Path:
arc1-ca.pugleaf.net!sparky!uunet!brunix!brunix!sdmReferences:
<1992Oct29.195546.1@vax1.bham.ac.uk> <1992Oct30.021207.3985@cs.brown.edu> <1992Oct30.051334.1016@frumious.uucp>Show Full Headers
Complete Article Headers
Newsgroups: comp.std.c++ Path: arc1-ca.pugleaf.net!sparky!uunet!brunix!brunix!sdm From: sdm@cs.brown.edu (Scott Meyers) Subject: Re: implicit pointer of pointer argument promotion legal C++? Message-ID: <1992Oct31.031431.6863@cs.brown.edu> Sender: news@cs.brown.edu Organization: Brown University Department of Computer Science References: <1992Oct29.195546.1@vax1.bham.ac.uk> <1992Oct30.021207.3985@cs.brown.edu> <1992Oct30.051334.1016@frumious.uucp> Date: Sat, 31 Oct 1992 03:14:31 GMT Lines: 42