2008年5月19日星期一

function declartion , function definition

Do you know what is different between function declaration and function definition?
If not, please google it first.

Some programmer is lazy to ignore the importances of function declaration, they may
neither not include header file or extern to declare the function before use.
For example, there is a function definition in a.c
void aaa(void)
{
printf("aaaa\n");
}
corresponding declaration
void aaa(void);
in a.h header file.

They will call aaa in any x.c xxx.c , without include a.h or extern void aaa(void) before use.

The consequence will be nothing, or system crash depending how you invoke aaa,
since all the following will be valid during compile time.
aaa(b);
aaa(b,b,b);

There is an example warning during compile time.
warning C4013: 'aaa' undefined; assuming extern returning int

Good practice
1. declare function before use, include header or extern
2. check all the warning

Exercise for you
1. Check my statement correctness, under what situation the system will reset and why.

沒有留言:

發佈留言