Find the answer to your Linux question:
Results 1 to 2 of 2
I thought I'd increase my knowledge of compilation and linking technologies, so I thought I'd ask you all this question. When I declare a function in C, how does the ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Linux Engineer Javasnob's Avatar
    Join Date
    Jul 2005
    Location
    Wisconsin
    Posts
    942

    How does the C compiler find function definitions?


    I thought I'd increase my knowledge of compilation and linking technologies, so I thought I'd ask you all this question. When I declare a function in C, how does the compiler/linker know where to find the definition. For example, if I declare a function with the same parameters and return value as free(), and I don't implement it, will the compiler use free declared in stdlib, or will it complain because I didn't include it?

    Thanks!
    Flies of a particular kind, i.e. time-flies, are fond of an arrow.

    Registered Linux User #408794

  2. #2
    Just Joined!
    Join Date
    Oct 2005
    Location
    Mass
    Posts
    52
    c programming 101:

    if you declare it as
    Code:
    void free(void *);
    somewhere and decide to
    Code:
    free(ptr);
    elsewhere without implementation then you'll have an error

    however if you try to
    Code:
    extern void free(void *);
    and link with c standard libraries then it will use stdlib free

    if you
    Code:
    #include "stdlib.h"
    void free(void *);
    then you'll have an error

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •