Day: GNOME OS
Posted Aug 10, 2012 10:57 UTC (Fri) by
jwakely (subscriber, #60262)
In reply to:
Day: GNOME OS by mathstuf
Parent article:
Day: GNOME OS
If C++ hadn't supported C casts (or had used a FFI for C interop, as you suggested above) it would never have achieved the success it enjoys today, which only happened by building on C's popularity and success. C compatibility is sometimes a millstone around the neck of C++ now, but without it this discussion probably wouldn't even be happening.
Without supporting C-style casts you couldn't write something as simple as this and have it be valid in both C and C++:
int* p = (int*)malloc(n*sizeof(int));
It's the right design for a C-style cast to invoke a user-defined conversion if one exists, for the reasons nix gives.
Why would you want to use C-style casts in templates anyway? Code in templates doesn't need to be C-compatible. You can't cast between arbitrary POD types anyway, in C or C++. Can you give an example that shows what you mean?
(
Log in to post comments)