What does the C standard say about...

  • Thread starter Kenny McCormack
  • Start date
K

Kenny McCormack

Suppose I include a declaration of a function, like:

int foo(void);

in my code, but do neither of the following:

1) Call foo()
2) link in a library that supplies foo()

My testing indicates that this is fine, but I'm curious what the standards
jockeys have to say.

BTW, this problem arises when you must include an include file that defines
some stuff you need, but also contains declarations for functions you don't
have (i.e., don't have the libs for).

--
But the Bush apologists hope that you won't remember all that. And they
also have a theory, which I've been hearing more and more - namely,
that President Obama, though not yet in office or even elected, caused the
2008 slump. You see, people were worried in advance about his future
policies, and that's what caused the economy to tank. Seriously.

(Paul Krugman - Addicted to Bush)
 
K

Kaz Kylheku

Suppose I include a declaration of a function, like:

int foo(void);

in my code, but do neither of the following:

1) Call foo()
2) link in a library that supplies foo()

If you do not call foo or take its address, then there is no reference
to foo.

If an identifier declared with external linkage is used in an expression
(other than as part of the operand of a sizeof operator whose result is an
integer constant), somewhere in the entire program there shall be exactly one
external definition for the identifier; otherwise, there shall be no more
than one. (C99 6.9)

No more than one means zero or one.

A similar text is given for internal linkage names, in the Constraints
section. This means that for internal linkage, a diagnostic is required
when these rules are violated, but for external names, a diagnostic is
not required (because the errors can arise after separate compilation,
at the linking stage, and there are linkage models which are loose, allowing
multiple definitions.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top