R
Ravishankar S
Dear C Experts,
While prepating a content for a C course,I made section on function
prototypes.
Could you kindly provide me your comments on its correctness. Thank you !
Q12: What is the difference between a function prototype and a function
declaration?
If you get this right, you must have done fair amount of research on C
programming beginning with "K&R" C. It turns out that function declarations
and function prototypes are the same thing in standard C. In K&R C a
function declaration did not need to have the types of its arguments to be
specified.
Thus a declaration like:
int Spi_Tx();
was perfectly acceptable, even though its definition was infact:
int Spi_Tx(uint8 TragetId,uint8 byteArray[],uint16 count)
{
}
It was easy for programmers to call the function with incorrect
parameters which needless to say had disastrous runtime consequences. Thus
ANSI C mandates function prototypes as the method for function declaration.
Regards,
Ravishankar
While prepating a content for a C course,I made section on function
prototypes.
Could you kindly provide me your comments on its correctness. Thank you !
Q12: What is the difference between a function prototype and a function
declaration?
If you get this right, you must have done fair amount of research on C
programming beginning with "K&R" C. It turns out that function declarations
and function prototypes are the same thing in standard C. In K&R C a
function declaration did not need to have the types of its arguments to be
specified.
Thus a declaration like:
int Spi_Tx();
was perfectly acceptable, even though its definition was infact:
int Spi_Tx(uint8 TragetId,uint8 byteArray[],uint16 count)
{
}
It was easy for programmers to call the function with incorrect
parameters which needless to say had disastrous runtime consequences. Thus
ANSI C mandates function prototypes as the method for function declaration.
Regards,
Ravishankar