On 12/31/19 3:13 AM, Jens Alfke wrote:
On Dec 30, 2019, at 6:23 PM, Alexander Vega <amve...@mail.usf.edu> wrote:
-fdevirtualize
-fdevirtualize-speculatively
I believe those are C++ optimizations, specific to C++ virtual methods. What
SQLite is doing is similar to a class with virtual methods, but done “by hand”
in plain C, so the optimizer doesn’t know how to apply that optimization.
(I’m fighting the urge to write an off-topic rant about why anyone still
programs in C when they could write roughly the same code much more simply and
cleanly in C++ using only the most basic features like classes and methods.
I’ve spent too much time lately trying to figure out or debug hellacious C
spaghetti code that’s awkwardly reinventing wheels like inheritance and
constructors/destructors.)
And in any case, de-virtualization only works when a virtual method has only
one implementation, I.e. is monomorphic, and that isn’t true here.
—Jens
I will give a short answer, in my opinion, of a few reasons on why C is
still a viable language.
1) The C API between separate compilations is very well established, and
fully documented in most environments. C++ is less so, where sometimes
important details like how to mangle names and occasionally handle
exceptions not fully standardized between compilers on a given platform.
2) The way language support packages work, it is fully defined to have a
C library in a C++ program, but it might not work to have a C++ library
in a C program, you need to have a C++ compatible startup package (to
run the constructors etc.). Changing a library from C to C++ is thus a
backwards breaking change unless EVERYONE has migrated to C++.
3) The C language is much more stable. While some new features have been
added to C in the last decade, the language has been very stable (yes,
some legacy features that were included in C90 were later removed but
that was for things that weren't recommended anyway). It is quite
possible to have a code base designed to build on a C99 implementation
(or even C90, perhaps with a few replacement headers like stdint.h for
some very useful additions from C99) and have it still work with a
totally up to date system. The C++ language has been much more fluid in
language definition.
4) There still exists some embedded system that don't have a free C++
compiler, so such a change restricts it from some environment
(admittedly, many of those may not have the resources to use SQLite well).
As an aside for that, SQLites 'virtual' functions aren't implementing
something easy to do in C++ (except by doing the same thing), as to do
what is being done you would have to change the 'type' of the SQLite
'object'.
--
Richard Damon
_______________________________________________
sqlite-users mailing list
sqlite-users@mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users