what's the use of the extern on the statement?:
>> extern int function (int *)
what's the different between :
1 - extern
2 - register
3 - ... and others.
what's the use of the extern on the statement?:
>> extern int function (int *)
what's the different between :
1 - extern
2 - register
3 - ... and others.
> >> extern int function (int *)
The extern keyword in this declaration is redundant. Functions are extern by default, meaning that they can be accessed from other source files. The two following declarations are equivalent:
extern int function ( int * );
and
int function ( int * );
Now, you can restrict access for the function to the file it is declared in by declaring it as static:
static int function ( int * );
This means that the function can only be used in the file that it was declared in.
Both extern and static have different meanings when used with variables in different scopes. A variable declared extern means that the variable was defined elsewhere and it can be used without an explicit definition in the source file where it is used. When static is used on a variable in global scope the meaning is the same as for a function, but when used in a local scope the variable will retain its value between function calls as if it were a global variable:
The output of this program isCode:#include <stdio.h> void func ( void ) { static int i = 0; printf ( "%d\n", i++ ); } int main ( void ) { func(); func(); getchar(); return 0; }
0
1
If i were not declared as static then the output would be
0
0
because the variable would be redefined and initialized to 0 with each call. When declared static, i is only initialized once and retains any changes made to it between calls.
The register keyword is a hint to the compiler that the variable will be used a great deal and the programmer thinks that it should be placed in a register for faster access. However, the compiler can and often does ignore this hint. Also note that a register variable may only be declared in local scope and you can't take its address.
The auto keyword is completely redundant and shouldn't be used since it can only be used in local scope and all local variables are auto by default. This keyword is really only useful for compiler writers, so you can safely forget it exists.
-Prelude
My best code is written with the delete key.