--- James Dennett <[EMAIL PROTECTED]> wrote: > Joe Wilson wrote: > > The proposed expression ((sqlite3_destructor_type)-1) is equivalent to > > ((void(*)(void *))-1). They are interchangable. > > Not in C++. The difference being linkage; with the typedef declared in > an extern "C" block, the type is something that can't be written > directly.
Now I understand your confusion. SQLite is a C. All its API definitions in sqlite3.h and its function pointers are obviously C-based. So to avoid these warnings related to using SQLITE_TRANSIENT (or SIG_ERR for that matter) in your C++ code, your C++ implementation file must do the following: // example.cpp #include "sqlite3.h" extern "C" { void example(sqlite3_context* c, const char* b, int n) { sqlite3_result_text(c, b, n, SQLITE_TRANSIENT); } // you can even put class member function implementations in here // i.e., void Foo::bar() {...} // without affecting their C++ linkage. } You'll find that it compiles in Sun C++ 5.8 2005/10/13 without warnings using the unmodified sqlite3.h file. The C++ code does not need the proposed typedef to handle SQLITE_TRANSIENT, although if it were added to sqlite3.h it would not do any harm, and you might be able to avoid the extern "C" block around your sqlite-related function implementations. > > #define SIG_IGN (void(*)(int))1 > > #define SIG_ERR (void(*)(int))-1 > > > > Such C code is grandfathered in C++. If it wasn't you wouldn't be able > > to do any UNIX systems programming in C++. > > It's not portable C, and it's not portable C++. It does seem to be > blessed by POSIX, but POSIX is just a subset of the much larger range of > platforms supported by ISO/ANSI C and C++. In your original question you asked: On a related but separate note, is there any standard that guarantees that casting -1 to a function pointer type is reasonably portable? And yes, it is reasonably portable as shown by every UNIX variant that must deal with POSIX and every major C++ compiler vendor, as a consequence. That's good enough for me. It may or may not be blessed by the C++ standard, but if you can dig up a modern popular C++ compiler that does not work with such code, I'd be surprised. ____________________________________________________________________________________ The fish are biting. Get more visitors on your site using Yahoo! Search Marketing. http://searchmarketing.yahoo.com/arp/sponsoredsearch_v2.php ----------------------------------------------------------------------------- To unsubscribe, send email to [EMAIL PROTECTED] -----------------------------------------------------------------------------