I have been coding in C for a very long time, and I thought I had it all figured out, until I saw this code in an MD5 library:
static void MDPrint (mdContext)
MD5_CTX *mdContext;
{
int i;
for (i = 0; i < 16; i++)
printf ("%02x", mdContext->digest[i]);
}
static void MDString (inString)
char *inString;
{
MD5_CTX mdContext;
unsigned int len = strlen (inString);
MD5Init (&mdContext);
MD5Update (&mdContext, inString, len);
MD5Final (&mdContext);
MDPrint (&mdContext);
printf (" \"%s\"\n\n", inString);
}
I am using gcc to compile it in Linux, and it works fine. The part that surprised me was the function structure. They are declaring type-less inString and mdContext within the parenthesis, and immediately after that they are redeclaring them as variables floating outside the function body.
I looked in all the C literature thinking maybe I skipped a chapter somewhere a long time ago, but no C reference shows this style of function structure. I googled every combination of keyword that could think of, but there is no mention anywhere.
So here are my questions:
1) What are the rules of this function structure? A link to a website explaining it would be awesome.
2) What are the advantages of this function structure? Are there disadvantages?
2.A) If there is no difference, Is it just a style of writting parameters? Is there an advantage to the style itself?
2.B) Is there any difference in the machine code generated by the compiler between this style and the standard style?
3) Is there a name or term to this function structure? If so what is it?
4) Is this standard C or is this a gcc extension of some sort?
Thanks for your help.