user2988694
user2988694

Reputation: 89

How many passes does a c compiler do?

int main()
{
    int res;
    funcAdd(10,20);
}

int funcAdd(int a,int b)
{
    return a+b;
}

In the above program, main does not recognize funcAdd() since it is defined after main and there is no declaration in the beginning. If C compiler did 2 passes of a program then this must not be an issue since it will know the function funcAdd() is be defined in the second pass. Does this mean C is one pass compiler? Kindly clarify my doubt.

Upvotes: 1

Views: 406

Answers (2)

user3553031
user3553031

Reputation: 6214

The C language doesn't specify how many passes a compiler must take. However, it /does/ specify that functions must be declared before they are used. Hence, your code is invalid, regardless of how many passes the compiler makes.

Upvotes: 11

David Schwartz
David Schwartz

Reputation: 182769

Your reasoning is invalid. A C compiler can make as many passes as it wants, but it still must return an error in this case because the standard says so.

Upvotes: 2

Related Questions