undefined functions

So I found a bug (it's probably shouldn't really be "important" but I do include a fix). I know why this bug happens, undefined functions are assumed to return an int, so it chops off the top of a 64 bit pointer.

but why? delving into the standards is tricky. first some terms

  • a function declaration gives the function name and the paramaters. It has a return type, a name and a paramater list. Each of the paramaters is possibly named (C99 6.7.5.3.6 : ...specifies the types of, and may declare identifiers for, the parameters of the function and later, C99 6.9.1 : If the declarator includes a parameter type list, the declaration of each parameter shall include an identifier). It looks like

    int afunction(int aparamater)
    

    .

  • a function prototype is like a weak version of a function declaration. It specifies the return value and the paramaters, but doesn't give the paramater names (C99 6.2.1 : A function prototype is a declaration of a function that declares the types of its parameters). This is used for C++ compatability, I think. It looks like

    int afunction(int)
    

    So you can say a function prototype is always a function declaration, but a function declaration isn't always a prototype.

  • a function definition is where you actually write the function. It looks like

    int afunction(int aparamater) { return aparamater; }
    

    Note that a function definition is also a declaration, which is why you can happily use functions after they are defined in the source code.

Ian Lance Taylor suggested the relevant part of the C99 standard dealing with undefined functions says

6.5.2.2; Paragraph 1 : The expression that denotes the called function shall have type pointer to function returning void or returning an object type other than an array type.

The disallows undefined functions by omission; they're not mentioned so they're not allowed. Actually, a little earlier when defining exactly what an expression is (6.5.1.2) we get one definition of a primary expression

An identifier is a primary expression, provided it has been declared as designating an object (in which case it is an lvalue) or a function (in which case it is a function designator)76 76: thus, an undeclared identifier is a violation of the syntax.

An undeclared identifier is not considered a primary expression. What's an expression? Think of it as anything that can go to the right hand side of an = or as the conditional of an if( ) statement.

So, a function declaration is just another type of declarator (C99 6.5.7) which declares an identifier which is the function name (e.g. in the same way int i declares i as being an identifier of integer type, int function(void) declares function() as an identifier of a function that returns int taking no arguments).

Ian Lance Taylor goes on to say

Given traditional C usage, requiring a function declaration can be reasonably viewed as a pedantic requirement, appropriate for -pedantic-errors. In general, if you want gcc to enforce strict adherence to the relevant standard, you must use -pedantic-errors. Of course there is a very reasonable coding style in which functions should always be declared for use. For that coding style, there is -Werror-implicit-function-declaration.

The only problem with this is that no one ever actually turns on those flags, and on 32 bit system (which most of the world use) it doesn't cause an error because the pointer is the same size as an int.

xchat notifier

In a previous post I mentioned I wanted an IRC notifier; I got the notifier working but can't really plug it into xchat.

As far as I can tell (and I didn't look that much, the only way I can get the notifier to fire when xchat matches my username in a message is to use the sound infrastructure. Each event can have sound play, and you can specifiy the program to play the sound. Thus I use this with a bogus filename like " You've got a message" ... the only problem is the box has the full path to the filename in it.

xchat must have a better way to handle this sort of thing ...

gnome-notify

IRC is a great way to communicate, but unless you sit around all day watching the screen or have headphones in to ping a sound when someone talks at you, it's easy to miss conversations. What I wanted was some way to pop up a notifier box at the bottom of the screen saying something like "you've got a new message". google searches for "gnome-notifer" didn't turn up anything great; except for a blog entry by Miguel de Icaza.

Looked like what I wanted but firstly it had a few bugs and by default left the message for 5 seconds then made it disappear. I wanted something that would leave the message until I indicated for it to disappear.

So I updated it to iron out some bugs and made it so that the message stays until you mouse over and out of it (the border changes so you know which messages are about to clear : screenshot).

Jazz Piano Comping for the Beginning Jazz Improvisor

Jazz Piano Comping for the Beginning Jazz Improvisor - Tom Anderson

I got this book on Amazon.com because I wanted to learn more about how to comp chords, thinking it might give me more of a harmonic framework when soloing.

It's not quite what I wanted ... I think I missed the "beginning jazz improvisor" and thought it was "beginning jazz piano comper". I'm no expert but I know my way around the basics; it starts right at the beginning and goes through chord theory, starting with majors and moving on to sevenths etc. At the end of each chapter is a written out song with voicings of mainly the type of chord the previous chapter talked about (I think they've done the same thing as the Jerry Coker "Improvising Jazz" book where the changes are for common songs but the title and written melody is different to avoid copyright).

That said, if I can find more time to learn the voicings in the chapters and make my way through the book it will be useful. If you do actually fit the title, it's probably to a bad, cheap buy.

unlimited-space.com

I've been through my fair share of cheap webhosts, and for the most part you get what you pay for. Since most of my sites are for hobby, downtime isn't too much of an issue for me.

However, I can so far say that unlimited-space.com has been a fantastic cheap webhost. They offer a full control panel so you can do most everything yourself, "unlimited" disk space, suitable bandwidth limits, and good features standard features like email, ftp users, mysql and an add-on domain. I've never even had to call on them for service, which for mine is a good sign. However last time I signed up an account it was ready in just a few hours.

You can also pay in $AU which is great. The only downside is the upfront payment -- often with the cheaper reseller based hosting services you pay upfront and never know how much service you're going to get. I have however had no problems with service quality and now have at least three sites running with them.

hnb - bad code

for an example of how not to do things, hnb is pretty good. it's a shame, because it looked like a handy, console based todo list with an xml backing. I don't mean to trash opensource work, but here's some constructive critisim

  • the code follows no known standard coding convention.

    indent(1L)
    

    can help you there

  • whenever you use the magic cast operator in C, be really really sure you know what you are doing.

    Node *pos=(Node *)data;
    ...
    return (int)pos;
    

    The code does this at least a hundred times! Obviously some code that was copied from somewhere but renders the program usless on any 64 bit machine, where sizeof(int) != sizeof(pointer). This also says something about abstraction, since it does it so many times this really hints it should have been broken out.

  • If someone says "XML", think Python, Perl, Ruby ... anything but C

weex

weex is an ftp synchronisation tool. It is fantastic. Here's my weexrc

[blog]
        HostName = ftp.wienand.org
        IgnoreLocalDir = CVS
        DestDir = /public_html/technovelty/
        LoginName = login_name
        Password = password
        SrcDir = /home/ianw/programs/junkcode/blog
        IgnoreRemoteFile = {
        *.py
        *.pyc
        *.html
        *.css
        *.cgi
        .htaccess
        .ftpquota
        }
        IgnoreLocalFile = {
        newentry.sh
        *~
        }
        IgnoreRemoteDir = {
        Pyblosxom
        plugins
        }
        IgnoreLocalDir = {
        *CVS*
        }
[default]

Then I just run

weex blog

and we're updated! In fact I might just do it now ...

junkcode repository

i've started my junkcode repository, storing it in CVS. this is less than ideal, as I can see me having work in three locations -- my laptop, my work machine and my home machine. the cvs repository lives on my house server, which should be accessable via internet at any time which should aleviate most of the issues. as i have full access to the canonical respository I can clean it up if things go astray too (something you can't do with sourceforge for example). what i would really like is the ability to push and pull between trees without having to learn arch. I'm not the only one, and Martin Pool has just started work on it.

In the mean time, if I'm getting into issues where I know I'll be with the laptop and want to check stuff into the repository with no net, I'll probably set up something that replicates the junkcode cvs root and modifies

CVS/Root

and uses rsync or something