-1

I am using the SDBM hash function in a program and have a question regarding the function definition, reproduced below:

static unsigned long
sdbm(str)
unsigned char *str;
{
    unsigned long hash = 0;
    int c;

    while (c = *str++)
        hash = c + (hash << 6) + (hash << 16) - hash;

    return hash;
}

I understand by trial and error that the function is expecting an unsigned char *, but why place it after the brackets and before the curly brace? I didn't know this was an option, and I can't find anything to tell me why it's not written like this instead:

static unsigned long
sdbm(unsigned char *str)
{
    ....
}

Of course, if I do modify it to be like this, the function still appears to work perfectly well, so why do it? What's the difference?

Sourav Ghosh
  • 133,132
  • 16
  • 183
  • 261
Steve Bunting
  • 419
  • 5
  • 12

1 Answers1

3

This is K&R method of function definition, nothing wrong, but obsolete. This was the way of function definition in pre-ISO era.

Technically,

static unsigned long
sdbm(str)
unsigned char *str;
{

is exactly same as

static unsigned long sdbm ( unsigned char *str ) {
Sourav Ghosh
  • 133,132
  • 16
  • 183
  • 261