0

I came across a code where the function definition is like this

void testname(input, arg0, arg1)
char *input;
{
    char buffer[BUF_SIZE];

    char *ptr;

    sprintf(testnamebuf, input, arg0, arg1);

    ptr = buffer;


    sprintf(ptr, "%s", testnamebuf);
}

Could someone explain me how the function definition is working? It's a weird way of defining the function and it's the first time I'm seeing such a code.

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
  • That's a K&R style function definition. In standard C, it would be `void testname(char *input, int arg0, int arg1) { … }`. It shouldn't have been written like that — `void` was added when prototypes were added. – Jonathan Leffler May 02 '18 at 06:13
  • Should we be horrified to learn that K&N style definition still exists in real codes? – taskinoor May 02 '18 at 06:15
  • I'm still fighting with an archaic code base that still has K&R functions in places — in code originally written when that was all there was. I'm actively working on cleaning up, but only a few hundred files still to go, with anywhere from 1 to 100 functions in the files. Grump! Yes, it horrifies me, but it is reality in some circles. (Of course, there are more problems than just K&R definitions — and most of those functions do have a prototype declaring the function, so it isn't quite as bad as it would be if that were not the case. – Jonathan Leffler May 02 '18 at 06:17

0 Answers0