question on key work "extern"(C prog)

This is a discussion on question on key work "extern"(C prog) within the Tech Board forums, part of the Community Boards category; Hello,all. I have just writed a example for practice the key word "extern" which is used in aspect of function. ...

  1. #1
    Registered User
    Join Date
    Jun 2006
    Posts
    22

    question on key work "extern"(C prog)

    Hello,all.
    I have just writed a example for practice the key word "extern" which is used in aspect of function.
    I typed it in a file that named main.c and the codes are shown as in following.

    error info:
    Code:
    /tmp/......
    undefined reference 'ret'
    main.c:
    Code:
    #include <stdio.h>
    
    extern int ret(int);
    
    int main(void)
    {
          int   i,j;
          printf("i:");
          scanf("%d",&i);
          j=ret(i);
          printf("\n%d\n",j);
          return 0;
    }
    test.c
    Code:
    int ret(int a)
    {
         return a*a;
    }

  2. #2
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    You need to compile both files together.

    Besides the extern keyword here has no effect. External linkage is the default for functions. It only has an effect with variables.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  3. #3
    Registered User
    Join Date
    Jun 2006
    Posts
    22
    thanks, CordneBee.How supernatural!It is so fun.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Window message loop (Keys)
    By Blackroot in forum Windows Programming
    Replies: 3
    Last Post: 09-12-2006, 05:15 PM
  2. Function to check memory left from malloc and free?
    By Lechx in forum C Programming
    Replies: 4
    Last Post: 04-24-2006, 05:45 AM
  3. C prog newbie question
    By Draginzuzu in forum C Programming
    Replies: 1
    Last Post: 02-03-2003, 05:45 PM
  4. Question about DNS (non prog but computers)
    By Windoze user in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 04-10-2002, 05:43 PM
  5. Replies: 8
    Last Post: 03-26-2002, 06:55 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21