6

Possible Duplicates:
C variable declarations after function heading in definition
What is useful about this C syntax?

I trying to understand some C code and came across this where variables are declared between the head of the function and the first brace.

Any Idea what these variables are?
Are they local or global?

What does the author intend to do here?

void someFunction (m_ptr, n_ptr, params, err)
            integer  *m_ptr;        /* pointer to number of points to fit */
            integer  *n_ptr;        /* pointer to number of parameters */
            doublereal *params;     /* vector of parameters */
            doublereal *err;        /* vector of error from data */
        {
            //some variables declared here
            int       i;
            ...
            ...

            //body of the function here

        }
Community
  • 1
  • 1
Kevin Boyd
  • 12,121
  • 28
  • 86
  • 128

3 Answers3

8

They are function arguments. This is an alternative way to declare them. They work the same way as normal arguments.

For a rather long but very informative explanation see Alternative (K&R) C syntax for function declaration versus prototypes

Community
  • 1
  • 1
terminus
  • 13,745
  • 8
  • 34
  • 37
3

Those variables are a declaration of the arguments. Not sure why anyone use that style any more. Those types must be typedef's though.

If this is old legacy code, did void really exist as a keyword back then?

onemasse
  • 6,514
  • 8
  • 32
  • 37
  • That explains it. I was a little bit confused by the void keyword, but it seems older compilers also supported that. – onemasse Dec 08 '10 at 06:53
2

That's a K&R-style declaration, and it's how C was written 30 years ago (it is still supported, but deprecated in C99; I believe that it will be removed in C1x). From the look of the types, the code was likely converted from Fortran, so who knows how old the original was.

It's not strict original K&R, however, because of the presence of void.

In "modern" C, that would look like:

void someFunction (integer *m_ptr, integer *n_ptr,
                   doublereal *params, doublereal *err)
{
    //some variables declared here
    int       i;
    ...
    ...

    //body of the function here
}
Stephen Canon
  • 103,815
  • 19
  • 183
  • 269