On Mon, 2010-10-11 at 16:37 -0700, Josh Triplett wrote: [....] > Wow. I had to double-check this because I couldn't quite believe C++ > had that degree of dain bramage, but sure enough: > > /tmp$ cat test.c > extern void *pv(void); > > int *pi(void) > { > return pv(); > } > /tmp$ gcc -c test.c -o /dev/null > /tmp$ g++ -c test.c -o /dev/null > test.c: In function âint* pi()â: > test.c:5: error: invalid conversion from âvoid*â to âint*â > (1) /tmp$ Welcome to one of the (more obvious) differences between C and C++: you can't assign/convert/promote a "void *" to any other pointer type (and vice versa) without explicit type-cast. For a library written in C, that is the point where "compile it also as C++" ends IMHO. Just keep the 'extern "C" {' stuff in headers (under '#ifdef __cplusplus') and compile it as C (and not C++). BTW there are other similar issues if one digs deep enough. BTDT (read: looked after a library which was used in 2 "applications" - one in pure C, the other C++. No way without explicit type-casts which look somewhat funny and are surely superfluous in C as such). > I can understand C++ having stronger typechecking, but void pointers > *exist* for this purpose. *Really* debatable whether Sparse should work > around this. Avoiding keywords, sure, but casting void pointers > everywhere? People *remove* these kinds of casts from C programs as a > cleanup. Type-casts are inherently evil. But in several situations there is in C no other (or better) workaround. The above - kill warnings through "void *" type-casts - makes it worse because some people (including /me) use the type system in C and want the compiler to check as much as possible. Bernd -- mobile: +43 664 4416156 http://www.sysprog.at/ Linux Software Development, Consulting and Services -- To unsubscribe from this list: send the line "unsubscribe linux-sparse" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html