What does the C standard say about...

Discussion in 'C Programming' started by Kenny McCormack, May 1, 2012.

  1. 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)
     
    Kenny McCormack, May 1, 2012
    #1
    1. Advertising

  2. Kenny McCormack

    Kaz Kylheku Guest

    On 2012-05-01, Kenny McCormack <> wrote:
    > 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.)
     
    Kaz Kylheku, May 2, 2012
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Dave Rahardja
    Replies:
    5
    Views:
    1,127
    John Harrison
    Jul 18, 2003
  2. Xenos
    Replies:
    1
    Views:
    325
    Rob Williscroft
    Jul 10, 2004
  3. Tobias Oed
    Replies:
    11
    Views:
    1,154
    Dan Pop
    Jun 30, 2003
  4. Sten Westerback

    Re: What does the standard say?

    Sten Westerback, Apr 2, 2004, in forum: C Programming
    Replies:
    3
    Views:
    421
    Rob Thorpe
    Apr 6, 2004
  5. r martin

    Re: What does the standard say?

    r martin, Apr 3, 2004, in forum: C Programming
    Replies:
    6
    Views:
    354
    Raymond Martin
    Apr 5, 2004
Loading...

Share This Page