OpenFest 2006 - Share the Freedom

February 03, 2004

It's the little things...

Grumble. Those who do not care about C++ and are just wondering what the hell is keeping me up at 2:40am may safely skip to the last paragraph.

The past hour (and a bit more, actually) was dedicated to figuring out why Visual Studio C++ would not "see" a symbol exported in a DLL (or rather, its export LIB) that it (well, *another* copy of Visual Studio :) had placed there just about 20 seconds ago. In the end, after using strings(1) on the .lib file, and very, very carefully reading the linker error message, it turned out that the .lib file mangled the function name as:

__imp_?uerror@@YAPAUUError@@HV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@0PAX@Z

...while the linker was actually looking for

__imp_?uerror@@YAPAUUError@@HV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@0PBX@Z

Spot the difference? Yeah, that's right - just a single puny character at the very end. Now, thanks to the creatively named Windows API function UnDecorateSymbolName(), I was able to find out that I'd forgotten to change a 'void *' to a 'const void *' in the function definition.

Yep, that's right, I'd made the most stupid mistake - the header file had 'const void *', the function itself took a 'void *' as a parameter... and why oh why didn't VC++ warn me at build time?! Yes, I am compiling with warnings at level 4; some of the time, I'm even adventurous enough to try /Wall - including this time, and no, VC++'s /Wall does not enable any warnings equivalent to GCC's -Wmissing-prototypes! If there is a discrepancy between the function declaration and the prototype, the compiler silently assumes that you actually want to declare a different function, and there you go.

Or wait a second.. Looking at it now, GCC only honors -Wstrict-prototypes and -Wmissing-prototypes when in C mode - for C++ files, you're on your own, too. Now if only I could figure out a reason for that... I mean, overloaded functions are all fine and dandy, but sometimes, just sometimes, I actually want the compiler to scream bloody murder at me for forgetting a tiny little 'const' thingy. If somebody has any idea why GCC will always silently accept a missing prototype in C++, and why VC++ does not even have a warning for that (well, it *is* mainly a C++ compiler), please enlighten me!

Grumble. Okay, back to the rest of the work now. And for those who find working at 2:40am strange, I seem to remember a saw that went something like 'Developers do not have office hours; all they have is deadlines'.

Posted by roam at February 3, 2004 02:40 AM

Comments

You know, I think that's a brill example of just why I fell in love with Java, and specifically Eclipse/IDEA. It brings new meaning to the phrase "intelligent tools". Kinda wish they made it for Perl and C as well...

Posted by: kay at February 16, 2004 02:39 PM

I don't think I should express an opinion on this point, since I have absolutely no experience with Eclipse and little to none with Java (mostly hearsay, although some of it from arguably authoritative sources, some browsing of existing code, never really tried to write anything myself). However, there are a couple of points that might still be worth mentioning - or questions that might be worth asking, so I can actually *form* an opinion :)

First of all, isn't Eclipse mostly an IDE, maybe a framework of libraries and such, but not a compiler by itself? The problem in this particular case was with the compiler not emitting a warning that it damn well should have, at least IMHO. So, unless Eclipse comes with its own compiler, it could not help in any way - the burden would be on the Java compiler, just as in this case it is on the C++ one.

Then we come to Java. As far as I know, in Java there is no way to declare functions or variables that are not part of a class. This alone makes the current situation impossible in Java, as well as in C# and in a couple of other pure OO languages: once you insist on all methods and variables being part of a class, it logically follows that the declarations of all methods and variables should reside in the declaration of the class, and there cannot be any others. In the current situation, the compiler sees a definition of a global function that has not been previously declared, and assumes that it will either be declared somewhere else, or that it can just go without a declaration - this is impossible if all functions are class methods, and the compiler can be sure that since it has not yet seen a declaration of this method, it can safely assume that it will never see one :)

Of course, one could argue that this makes the pure OO ideology superior to the ideology of a language which allows global functions and variables - and with this I have to agree. As noted above, I don't really know enough about Java to express an opinion, but Eiffel and C# strike me as wonderfully designed languages, which do indeed make many problems simply irrelevant (unthinkable, if you like). Still, there are things for which my language of choice will be C, and there are things (a few, and becoming even fewer with time) for which my language of choice will be C++... hence this blog entry's rant :)

Posted by: Peter Pentchev at February 17, 2004 01:58 PM

The point was that developer tools are normally "supposed to be hard" to use, if you know what I mean. Just one example. IDEA actually includes it's own compiler and it compiles the code on the fly, as you type. Doing so, any mistakes it finds are highlighted in an unintrusive manner. Most of the time you can even right click on the offending statement and one or more fixes to the problem will be suggested - just like fixing a spelling mistake in a recent word processor. What's amazing is not that it can be done - just why hasn't anyone done it before. It's a complete change of attitude towards you as the developer. "Let's make writing code a pleasure." Oohh... that's a novell idea! :-) Seriously, give it a spin. I know it's 50 megs but you'll be impressed.

http://jetbrains.com

Eclipse is an open source project that mimics and at some levels competes with IDEA, but it's not as close. Still, it's an excellent Free and free alternative to IDEA for those who can't afford the license.

Posted by: kay at February 18, 2004 09:12 AM
TrackBack