1

Reading glibc, I saw this piece of code in string/strerror.c:

char *
strerror (errnum)
     int errnum;
{
  char *ret = __strerror_r (errnum, NULL, 0);
  int saved_errno;

  if (__glibc_likely (ret != NULL))
    return ret;
  saved_errno = errno;
  if (buf == NULL)
    buf = malloc (1024);
  __set_errno (saved_errno);
  if (buf == NULL)
    return _("Unknown error");
  return __strerror_r (errnum, buf, 1024);
}

Note how there is a int errnum following the argument list. How is this a valid syntax? And what is it doing?

Derek Chiang
  • 3,330
  • 6
  • 27
  • 34

1 Answers1

1

That's the old-style way of doing things, K&R, pre-ANSI.

Once function prototypes were introduced, this way of doing things was rendered obsolete.

Not actually obsolete since it's still valid even in C11 (as per 6.9.1 Function definitions /13), but few people use it any more).

It's specifying the type of the parameter for the function block, similar to:

char *strerror (int errnum)
paxdiablo
  • 854,327
  • 234
  • 1,573
  • 1,953
  • Under K&R all arguments were integers in the declaration `strerror (errnum)`, then type defined on the next line as I understand it. – David C. Rankin Jun 27 '14 at 05:02