What weird C syntax is this? [duplicate]
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
开发者_如何学Go }
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
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?
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
}
精彩评论