Does the order of objects C?

Does the order in which C objects appear in the file are described?

For example, in functions, if I create two functions, and one of them refers to the other, will it work? (Yes, I tried it.) Does the same apply for static functions, INLINE functions, etc.? The same for structures? What happens if I refer to the structure that is further specified in the .c file?

Is this any specificity for the compiler? How does the compiler work in this case? Does it first check the entire file for all declarations / definitions, and then try to dereference functions / characters?

+3
source share
4 answers

-, " , , ?" - :

int foo()
{
    return bar();
}

int bar()
{
    return 0;
}

bar(), , , , bar() . , (, ), , .

C, ( : , , ..), . , (, , static, inline ), .

. , ; , .

, :

int bar() { return 4; }

, , () .

:

int bar();

, , . C ( ), .

, :

int foo();
int bar();

int foo()
{
    return bar();
}

int bar()
{
    return 0;
}

C .

+3

, - , . - .

, , .

int trol(int a, int b);

// use trol(int, int)

int trol(int a, int b) { }

, a b, : a, b, b a. a , , b. .

- , , . , : C?

struct s ( ), :

struct s;

// use s*'s

struct s { };

( , , struct , , .)

+2

, , , - "" ( int foo() ), - ( , , ).

( ) ( , ).

(, printf) . , :

int foo(int a)
{
    b(a);
    b("hello", "kitty");
}

void b(int a, ...)
{

    printf("%d", a);
}

- :

#include <stdio.h>
int foo(int a)
{
    return b(a);
}

int b(int a)
{

    return printf("%d", a);
}

( )

, - (forward declarations), , .

+1

, C "" , . , , , , , . , :

Object Declaration
...
Object Reference
+1
source

All Articles