Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9241951
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T08:28:37+00:00 2026-06-18T08:28:37+00:00

Possible Duplicate: Effects of the `extern` keyword on C functions Ok, so for a

  • 0

Possible Duplicate:
Effects of the `extern` keyword on C functions

Ok, so for a few hours now I’ve read a lot about what the extern keyword means. And there is one last thing that is bugging me to no end that I cannot find any info about.
As far as I understand the extern keyword basically tells the compiler that the variable or function is only a declaration and that it is defined somewhere, so it doesn’t have to worry about that, the linker will handle it.

And the warning generated by the compiler (I’m using gcc 4.2.1) when typing this:

extern int var = 10;

supports this. With extern this should be a declaration only so it is not correct.

However, the thing that is confusing me is the absence of a warning or anything when typing this:

extern int func() {return 5;}

This is a definition, and it should generate the same warning, but it does not. The only explanation to this I was able to find here is that the definition overrides the extern keyword. However, following that logic why does it not override it when it is a variable definition? Or does the keyword have special meaning when used with variables?

I would be most grateful if someone explained this to me. Thank you!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T08:28:39+00:00Added an answer on June 18, 2026 at 8:28 am

    The extern keyword indeed has special meaning only when it is used with variables. Using extern with function prototypes is entirely optional:

    extern void foo(int bar);
    

    is equivalent to

    void foo(int bar);
    

    When you declaring/defining a function, you have two options:

    1. Provide only a declaration (i.e. a prototype), or
    2. Provide a definition, which also serves as a declaration in the absence of a prototype.

    With variables, however, you have three options:

    1. Provide only a declaration,
    2. Provide a definition with the default initializer: int var; without the = 10 part, or
    3. Provide a definition with a specific initializer: int var = 10

    Since there are only two options for functions, the compiler can distinguish between then without the use of extern keyword. Any declaration that does not have a static keywords is considered extern by default. Therefore, the extern keyword is ignored with all function declarations or definitions.

    With variables, however, the keyword is needed to distinguish between the #1 and the #2. When you use extern, it’s #1; when you do not use extern, it’s #2. When you try to add extern to #3, it’s a warning, because it remains a definition, and the extern is ignored.

    All of this is somewhat simplified: you can provide declarations several times in the same compilation unit, and you can provide them at the global scope or at a block scope. For complete details, check section 6.7.9 5 of the C standard.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Is there any way to hover over one element and effect a
Possible Duplicate: jQuery: interrupting fadeIn()/fadeOut() the fade effects in jQuery are really smooth, there's
Possible Duplicate: Is there any way to undo the effects of “git revert head”?
Possible Duplicate: Why use document.write? Considering the negative effects of document.write(), why are most
Possible Duplicate: Objective C for Windows iPhone development on Windows Is there any way
Possible Duplicate: How do JavaScript closures work? Javascript closures and side effects in plain
Possible Duplicate: Why is there no call to the constructor? What’s the effect of
Possible Duplicate: Is there a difference between (function() {…}()); and (function() {…})();? I have
Possible Duplicate: How to achieve code folding effects in emacs An excellent feature of
Possible Duplicate: How to loop a css background image with Jquery every few seconds?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.