7 Aug 2000 alex   » (Master)

I've been hacking some C++ 2D vector and matrix classes in preparation for a vector drawing program I'm planning to do. They are template expression based and therefore totaly unreadable. But they do generate kick ass code using the latest g++ snapshot.

Using the online snapshot compile form at codesourcery this function:

double dotty(Vector &x, Vector &y, Vector &z)
  return dot(x, y+z);
compiles to this (x86) code (using -O2 -march=pentiumpro):
        pushl   %ebp
        movl    %esp, %ebp
        subl    $24, %esp
        movl    8(%ebp), %eax
        movl    12(%ebp), %edx
        movl    16(%ebp), %ecx
        movl    %ebp, %esp
        fldl    (%eax)
        fldl    (%edx)
        fldl    8(%eax)
        fxch    %st(1)
        popl    %ebp
        faddl   (%ecx)
        fmulp   %st, %st(2)
        fldl    8(%edx)
        faddl   8(%ecx)
        fmulp   %st, %st(1)
        faddp   %st, %st(1)
which is pretty damn good for that (very readable) sourcecode. There is none of the normal problems with temporary objects etc.

Unfortunately i had to fight quite a lot with the template syntax, so the code isn't very nice. It would be a lot nicer if convertion operators were actually used when matching arguments to template functions. I wonder why that isn't in the C++ standard?

Latest blog entries     Older blog entries

New Advogato Features

New HTML Parser: The long-awaited libxml2 based HTML parser code is live. It needs further work but already handles most markup better than the original parser.

Keep up with the latest Advogato features by reading the Advogato status blog.

If you're a C programmer with some spare time, take a look at the mod_virgule project page and help us with one of the tasks on the ToDo list!