Why have to put prototypes and structure in every file using it in a program?

Can I understand it that way the prototypes and structures have the internal linkage by default?

ODR (One Definition Rule) applies to definitions. A prototype is the declaration (of a function); we can declare the same thing as many times as we want.

Types (for instance, structures) can be defined in more than one translation unit; but each translation unit can't have more than one definition and the definitions in different translation units must (logically) be the same.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
extern int i ; // declaration
extern int i ;
int i = 8 ; // definition (external linkage; only once in the entire program)
extern int i ;

int foo(int) ; // declaration
int foo( int a ) { return a*2 ; } // definition (external linkage; only once in the entire program)
int foo(int) ;

struct A ; // declaration
struct A ; // declaration
struct A // definition (type; only once per translation unit)
{
    // ....
};
struct A ; // declaration

int main()
{
}

Thanks!
And I meet another problem:

1
2
extern int a;//say a=5
static int a = 10;

Above I know it's internal linkage hides external one. But when I apply this rule to the code below, error!
1
2
static a=10;//internal linkage
a=5;//external linkage 

I guess it's because the ODR, but as I figured, internal linkage should hides external one. Why wrong?
This is an error:
1
2
extern int a;
static int a = 10;

http://coliru.stacked-crooked.com/a/f794db23dae347b0
Topic archived. No new replies allowed.