C function syntax, parameter types declared after parameter list?

That's the old-style syntax for parameter lists, which is still supported. In K&R C you could also leave off the type declarations and they would default to int. I.e.

That's the old-style syntax for parameter lists, which is still supported. In K&R C you could also leave off the type declarations and they would default to int. I.e.

Main(argc, argv) char *argv; { return 0; } would be the same function.

3 Both C89/90 and C99 still officially support K&R style declarations. However, in C99 all parameters have to be explicitly declared (no "implicit int" rule anymore). – AndreyT Oct 18 '09 at 17:12.

This is so caller K&R style or old-style declaration. Note, that this declaration is significantly different from the modern declaration. K&R declaration does not introuce a prototype for the function, meaning that it doesn't expose the types of the parameters to the outside code.

What's also interesting is the calling convention difference of functions with, and functions without a prototype. Consider an old style definition: void f(a) float a; { /* ... */ } In this case, the calling convention is that all arguments are promoted before being passed to the function. So f receives a double, but the parameter has type float, which is perfectly valid.

The compiler has to emit code that converts the double back to a float prior to executing the function's body. If you include a prototype, the compiler does not do such automatic promotions anymore, and data is passed as being converted to the types of the parameters of the prototypes as if by assignment. So the following is not legal and results in undefined behavior: void f(float a); void f(a) float a; { } In this case, the function's definition would convert the submitted parameter from double (the promoted form) to float because the definition is old-style.

But the parameter was submitted as a float, because the function has a prototype. Your options of solving the contradictions are the two following // option 1 void f(double a); void f(a) float a; { } // option 2 // this declaration can be put in a header, but is redundant in this case, // since the definition exposes a prototype already if both appear in a // TU prior to the call. Void f(float a); void f(float a) { } Option 2 should be preferred if you have the choice, because it gets rid of the old style definition up front.

If such contradicting function types for a function appears in the same translation unit, the compiler will usually tell you (but is not required). If such contradictions appear over multiple translation units, the error will go most possibly unnoticed and can result in hard to predict bugs. Best is to avoid these old style definitions.

While the old syntax for function definition still works (with warnings, if you ask your compiler), using them does not provide function prototypes. Without function prototypes the compiler will not check if the functions are called correctly. #include int foo(c) int c; { return printf("%d\n", c); } int bar(x) double x; { return printf("%f\n", x); } int main(void) { foo(42); /* ok */ bar(42); /* oops ... 42 here is an `int`, but `bar()` "expects" a `double` */ return 0; } When the program is run, the output on my machine is $ gcc proto.

C $ gcc -Wstrict-prototypes proto. C proto. C:4: warning: function declaration isn’t a prototype proto.

C:10: warning: function declaration isn’t a prototype $ . /a. Out 42 0.000000.

There is no difference, it is just that that is the old syntax for function declarations in C -- it was used pre ANSI. Never write such code unless you plan to give it to your friends from the 80's. Also, never depend upon implicit type assumptions (as another answer seems to suggest).

Well pre C99; it was used pre-ANSI, which was standardized in 1989 but the process began in 1983. – Brian Campbell Oct 18 '09 at 16:53 Thanks mate. Fixed it now... – Aviral Dasgupta Oct 18 '09 at 17:04 1 Ahem... K&R style declarations are still officially supported by C99, with just one minor change - no "implicit int" anymore, all parameters have to be explicitly declared.

– AndreyT Oct 18 '09 at 17:14 Amidst the criticism, I must say I agree with you: don't do it. – BobbyShaftoe Oct 18 '09 at 20:18.

Its just the same but old fashion. You probably found it is some old, legacy code.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions