question about declaring function extern

This is a discussion on question about declaring function extern within the C Programming forums, part of the General Programming Boards category; Hi. I see people declare functions as 'extern' in header (.h) files. Is this what I should be doing? someheader.h ...

  1. #1
    Linux is where it's at movl0x1's Avatar
    Join Date
    May 2007
    Posts
    72

    question about declaring function extern

    Hi. I see people declare functions as 'extern' in header (.h) files.
    Is this what I should be doing?

    someheader.h
    Code:
    /* someheader.h */
    
    extern int func(int a, int b);
    func.c
    Code:
    /* func.c */
    #include "someheader.h"
    
    int func(int a, int b)
    {
      return a * b;
    }
    I usually do the same as above, but don't put the 'extern' in front
    of the function declaration in the header file, and it seems to work.
    Is this ok, or should I prepend it with extern?

    thanks alot
    Remember that all that code you write turns into this:

    0100100100110010010011100100111001001
    0010100100100001001111100010010010010 ....

  2. #2
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,424
    functoins are by default extern - so you do not need to specify it explicitely...

    When function has a static linkage - you need to specify it explicitely... but in this case - you do not want to put the function prototype in the header.
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  3. #3
    Linux is where it's at movl0x1's Avatar
    Join Date
    May 2007
    Posts
    72
    thanks vart
    Remember that all that code you write turns into this:

    0100100100110010010011100100111001001
    0010100100100001001111100010010010010 ....

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. CreateThread() function question
    By chiefmonkey in forum C++ Programming
    Replies: 5
    Last Post: 05-15-2009, 07:52 AM
  2. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  3. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-29-2005, 11:21 PM
  4. c++ linking problem for x11
    By kron in forum Linux Programming
    Replies: 1
    Last Post: 11-19-2004, 09:18 AM
  5. structure vs class
    By sana in forum C++ Programming
    Replies: 13
    Last Post: 12-02-2002, 06:18 AM

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