Deprecated: Function create_function() is deprecated in /var/www/blog/inc/libs/clearbricks/common/lib.l10n.php on line 640

Deprecated: Function create_function() is deprecated in /var/www/blog/inc/libs/clearbricks/common/lib.http.php on line 249
OCCI-gateway, or why C++ is a horrible language - Grumpycoder
Flux RSS

OCCI-gateway, or why C++ is a horrible language

I don't really know to which category this should fit, but I guess "code rant" is probably quite appropriate. I'd like to discuss a bit about why C++ is a horrible language, by adding a few arguments towards Linus.

The exact reason why C++ is horrible for this article is that there's strictly no ABI or even any effort of standardization / specification. In particular, the exception system, the virtual tables, or even the function mangling to embed the argument's types into the symbol's name. That causes a very tedious problem: you can't properly export C++ code into any kind of library.

In plain C, if you export a function, then any compiler around should be able to link to it and use it. The call ABIs in both 32 and 64 bits have been fully specified, and there's no specific name mangling, leading to a clean import of library function to any other software. In C++, because of what I mentioned above, you just can't link anything that's been compiled using another compiler, and most of the time, you can't even link properly with a different version of the same compiler. So in order to share your library, the only safe and clean way to do it is to provide the source code so that anyone who wants to use your code can do it by simply recompiling it for his compiler. If you don't do this, and stick to providing only either static or shared library to your users, there's a high chance tears will be shed.

Here's an example: Oracle's OCCI. This is a quite powerful library that can enable you to access Oracle's databases using a quite clean and powerful interface. Its main advantage (against the existing OCI) is it's written in C++. The main problem is it's written in C++. Because, of course, they won't provide the source code for it. As a result, if you download Oracle's SDK, you'll notice that you have a common library directory with all the dlls, and then you'll have compiler-specific libraries directory containing only the OCCI objects. That's because of the problems I talked above. And of course, they didn't compile their library using every possible combination of compiler. For instance, the AIX version uses IBM's compiler only, the Solaris version uses (sic) Sun's C compiler, and the windows version uses MSVC 8 and 9 only. Note that MSVC10 will not work. It will compile and link though. It just won't work. And most of all, there's no mingw32 version. Bummer.

Which brings me to the main topic of that article actually: OCCI-gateway. This is a project I started and I still don't know if I want to fill it into my (quite large actually) "frankenstein-like experiments" folder, or into the "awesomesause" one. Probably in between. The main idea of OCCI-gateway is to provide the OCCI API to more compilers than what Oracle supports, especially mingw. The way it works is by creating a DLL that I've called "OCCI-MSVCgateway.DLL", that'll import most of OCCI.DLL's features, and export them into plain-C. So if you import this new DLL into your own code, you'll be able to call plain-C functions that'll then translate into C++. From there, there's another .cpp/.h pair that you can import into your mingw32 projet (or probably even MSVC10, but I haven't tested), that'll re-translate all of the C calls into a "OCCI_proxy" C++ namespace. That namespace should contain most of the OCCI classes, that just forward their arguments into the C DLL, transparently making you using OCCI within your non-supported environment.

I don't know if anyone else really tried to do something like this, or if it really had any point of doing this at all. My two main arguments for doing this were "hey, is this even possible ?", (which is the argument that motivates 90% of my projects actually), and the sake of portability for my linux-OCCI code. Now it works pretty well, and it seems other people started to use it. Which is somewhat scary. If I ever see this used into a real production environment, I still don't know if I'll feel shame or pride.

Fatal error: Uncaught Error: [] operator not supported for strings in /var/www/blog/inc/core/class.dc.postmedia.php:61 Stack trace: #0 /var/www/blog/inc/core/ dcPostMedia->getPostMedia(Array) #1 /var/www/blog/cache/cbtpl/29/59/2959320ca61719bec433f91e69098e86.php(137): dcMedia->getPostMedia('22', NULL, 'attachment') #2 /var/www/blog/inc/libs/clearbricks/template/class.template.php(268): include('/var/www/blog/c...') #3 /var/www/blog/inc/public/class.dc.template.php(231): template->getData('post.html') #4 /var/www/blog/inc/public/lib.urlhandlers.php(122): dcTemplate->getData('post.html') #5 /var/www/blog/inc/public/lib.urlhandlers.php(523): dcUrlHandlers::serveDocument('post.html') #6 /var/www/blog/inc/libs/clearbricks/url.handler/class.url.handler.php(166): dcUrlHandlers::post('2010/11/18/OCCI...') #7 /var/www/blog/inc/public/lib.urlhandlers.php(187): urlHandler->callHandler('post', '2010/11/18/OCCI...') #8 /var/www/blog/inc/public/prepend.php(156): dcUrlHandlers->getDocument() #9 /var/www/blog/ind in /var/www/blog/inc/core/class.dc.postmedia.php on line 61