Code
Using <complex> vs <complex.h> with g++
Posted by HokieTux on February 1, 2010 in Code, Hacks
Long story short: Including <complex.h> in your C++ source file does not include the C language complex.h header!
After fighting with g++ to get the proper complex numbers implementation working in a recent project of mine, I thought I would post what I discovered in case anyone else finds it useful.
It is fairly common knowledge that use of C-style standard headers in C++ is considered deprecated. By this I mean that if you want to include <stdio.h>, a C library, in a C++ source file, then you should actually include <cstdio>. The same exists for other libraries, e.g. <math.h> is <cmath>, <signal.h> is <csignal>, etc. This has been phased into recent versions of compilers with varying levels of enforcement.
However, not all standard C libraries have been moved over to the new standard. For a long while, <stdint.h>, which includes bit-specific datatype declarations like int32_t and uint64_t, did not have an equivalent <cstdint>. In these circumstances, including the originial <stdint.h> worked just fine, and included the C language header as expected.
This is not the case with <complex.h>.
The C++ standard implementation of complex numbers is a templated type. To declare it, you do something like:
complex<float> mynum(2.0, 3.0);
The C version of complex numbers is an IEEE standard (1003.1), and is declared like so:
complex double mynum = {2.0 + 3.0*I}
If you want to use the C version, you might think all you need to do is #include <complex.h> in a C++ file… turns out that doesn’t work. For whatever reason, g++ will include the C++ templated type rather than the standard C language type.
If you want to use the C version, the easiest way I’ve found is to simply give the absolute path to the include header, like so:
#include “/usr/include/complex.h”
I ended up using the C++ version anyways, but while I was attempting to use the C implementation, this one certainly had me confused for a bit.
vimrc updated
Posted by HokieTux on December 3, 2008 in Code, News
This is just a heads-up that the vimrc I provide via bzr (or via direct link) has been updated. Tom recently found a site or two that had some nifty settings I hadn’t stumbled across yet. Changes include:
- Now using smarter buffer-management via ‘set hidden’
- Window title will now make sense
- *** No longer have to scroll to bottom of screen for your screen to start scrolling! There is now a 15-line DMZ between your cursor and the bottom of the window! Sorry for the asterisks… but this is the feature I’m most excited about.
- Some smarter key mappings
- Menu-completions for command-mode options/commands
- Enabled the ‘matchit’ plugin (available in most repos)
There are a few other usability changes if you really feel like digging through it. If anyone has anything they think should be added, please post and let me know!
You can find the file here: http://git.hokietux.net/configs.git/blob_plain/HEAD:/global/vimrc
A Guide to Using Subversion
Posted by HokieTux on May 1, 2008 in Code, Guides
Using this topic as a blog article is cheating somewhat, since I’ve essentially already written it for another audience. However, it’s finals season (which should somehow justify my apathy in coming up with original material).
It has been my experience that most people don’t learn how to use a SCM (source code manager) until they are forced to, which is really quite tragic. SCMs have been a mature technology for some years now, and doing any sort of serious coding without using one is really just silly, if not dangerous.
Like everything else in the open source world, there is a large variety of SCMs to choose from. I will likely make a future blog post on DSCMs (distributed SCM), which are in many ways superior to non-distributed SCMs, like Subversion and CVS (if you are still using CVS, by the way, you may want to reconsider your Luddite methodologies…). Regardless, Subversion is widely used, and really is the best non-distributed SCM around.
And so, with that, here is a reference guide to using Subversion: