Sunday 13 November 2011

Should a variable’s type be declared within the header of a function or immediately following? Why? in C programming

Should a variable’s type be declared within the header of a function or immediately following? Why?

The ANSI standard is to declare a variable’s type within the header of the function. As you’ll discover in Chapter XX, C was originally designed to run on the UNIX operating system back in the ’70s. Naturally, this was before any sort of C ANSI standard. The declaration method for the original C compilers was to put the argument’s type immediately after the function header. 

Today, the ANSI standard dictates that the type be declared within the function’s header. The problem with the old method was that it didn’t allow for argument function type checking—the compiler could perform only return value checking. Without argument checking, there is no way to see whether the programmer isassing incorrect types to a function. By requiring arguments to be inside the function’s header, and by requiring you to prototype your functions (including the argument types), the compiler can check for incorrect parameter passing in your code.

Cross Reference:

XIV.11: Should programs always include a prototype for main()?

No comments:

Post a Comment