On Mon, 26 Aug 2013 16:07:13 +0100 Nick Treleaven nick.treleaven@btinternet.com wrote:
I now think gradually using a (quite heavily restricted) subset of C++98 for *some* source files might be better than moving to C99 [...]
Reasons:
- RAII - this is a pretty essential feature for safe resource
management.
This works for global/static and auto classes. We can wrap a gchar *s = g_strdup_printf() in a class, but I'd rather not... and you want to ban "class".
- References can be useful in making code more readable vs pointers.
But using both heavily (as GLib/GTK+ required pointers) will make it harder to read.
- Developer enjoyment, productivity & gaining more experience with C++.
(This might be an incentive for e.g. me to spend more time working on Geany). This has to be offset against those that might need to learn e.g. RAII.
Hmmm?..
- Possibly we might use some STL containers internally.
There things are heavily templated. They generate more code, compilation is slower, and (unless improved significantly from the last time I tried them) the code is overall slower than using GArray/GList. Moreover, you propose to ban "class".
- Possibly we could use a GObject wrapper for safe reference counting.
Why? Where? How to do that without classes and destructors? Note that gcc has a non-standard extension for RAII, which works with the base C types. And Geany compiles with gcc only.
- Possibly we could have some template function utilities instead of
unsafe macros.
Do we need these macros to work with different types? If not, "inline is already declared in a portable manner in the GLib headers and can be used normally."
We would also need to disable some C++ features. I hoped we could do that with g++ flags, but I've only found this so far:
-fno-rtti (disable runtime info for object inheritance)
+1. Earlier versions of Qt/KDE did that, don't know about current.
There ought to be a way to disable mixed code and declarations, but maybe not.
Not AFAIK.
I don't know if this can be enforced by g++, but I suggest we disallow these keywords:
class
There isn't, that's THE most basic feature of C++. And you can write classes with struct and union.
dynamic_cast
-fno-rtti
friend
No classes -> no usage for friends.
mutable operator
throw
-fno-exceptions
virtual
No classes -> no virtual methods.
Thoughts?
Sorry, but IMHO, that seems even more pointless than using C99.