At C lang FAQ I found the following code:
void f(ipp)
int **ipp;
{
static int dummy = 5;
*ipp = &dummy;
}
I tested compiling it with -Wall -std=c11 -pedantic
flags, and it compiled with no warnings or errors. How is that possible - a variable declared between the function name and its block?
Edit:
A few hours after posting, and after a number of answers, I find the question is closed as a duplicate. I don't agree with the decision to close. In fact, the duplicate Q&A and the answers given here so far, although broadly correct, don't answer my question specifically.
My query is about variable declarations appearing between a function name and its block. OK, that's the original K&R style, but I still find the location of the declarations shocking. Having read the K&R Second Edition book that describes ANSI C89, I was aware that the previous style allowed a different way of declaring function parameters, but AFAIK that book did not show the declarations being made in this way. Maybe it does and I have forgotten about it.
I believe it is good to have a question separately about this particular issue in case someone else gets thrown by it in the future. My question should stand for anyone who can shed some light on how it was decided to allow the parameters be declared in this strange location. The impression you get from C and all C-inspired languages is that nothing comes between a token and its block braces. My question draws attention to a significant exception that should be highlighted and its rationalle understood, even if it is 30/40 years old.
Edit 2:
I now find that C++ syntax allows for a token to come between the function name and its block. Even so, the idea of whole declaration lines coming in between is more severe and worth pointing out to C newbies as a quirk they might encounter. I have checked, and the K&R Second Edition book indeed does not explicitly mention this.