ieplugin
ieplugin

Reputation: 681

When is "undefined" fatal or just warning?

test.c(6) : warning C4013: 'add' undefined; assuming extern returning int

I've encountered many times when an undefined function will report an error,thus stopping the building process.

Why this time just a warning?

Upvotes: 1

Views: 151

Answers (3)

msw
msw

Reputation: 43517

Depending on your compiler, you can instruct it to treat warnings as errors. Although it may be inconvenient, this is often a good thing because the compiler knows more about the details of the code than you do.

In the GNU C suite -Werror is your friend. Offer void in Tuvalu.

Upvotes: 1

Jerry Coffin
Jerry Coffin

Reputation: 490408

In C++, attempting to call a function without a valid declaration in scope is an error (whereas C requires the compiler to accept it and make certain assumptions in such a case).

If you have an undefined external at link time (as opposed to compile time), that will also stop the build -- it the linker can't find a definition of a function you've called (or tried to call, anyway), so it can't produce an executable.

Upvotes: 2

Marcelo Cantos
Marcelo Cantos

Reputation: 185970

Perhaps you normally code in C++, and this is a C program. C++ is stricter than C; it won't let you call undeclared functions.

Upvotes: 4

Related Questions