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 9163943
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T14:33:47+00:00 2026-06-17T14:33:47+00:00

Why the following doesn’t compile? … extern int i; static int i; … but

  • 0

Why the following doesn’t compile?

...
extern int i;
static int i;
...

but if you reverse the order, it compiles fine.

...
static int i;
extern int i;
...

What is going on here?

  • 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-17T14:33:48+00:00Added an answer on June 17, 2026 at 2:33 pm

    This is specifically given as an example in the C++ standard when it’s discussing the intricacies of declaring external or internal linkage. It’s in section 7.1.1.7, which has this exert:

    static int b ; // b has internal linkage
    extern int b ; // b still has internal linkage
    
    extern int d ; // d has external linkage
    static int d ; // error: inconsistent linkage
    

    Section 3.5.6 discusses how extern should behave in this case.

    What’s happening is this: static int i (in this case) is a definition, where the static indicates that i has internal linkage. When extern occurs after the static the compiler sees that the symbol already exists and accepts that it already has internal linkage and carries on. Which is why your second example compiles.

    The extern on the other hand is a declaration, it implicitly states that the symbol has external linkage but doesn’t actually create anything. Since there’s no i in your first example the compiler registers i as having external linkage but when it gets to your static it finds the incompatible statement that it has internal linkage and gives an error.

    In other words it’s because declarations are ‘softer’ than definitions. For example, you could declare the same thing multiple times without error, but you can only define it once.

    Whether this is the same in C, I do not know (but netcoder’s answer below informs us that the C standard contains the same requirement).

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

Sidebar

Related Questions

I'm trying to use STL, but the following doesn't compile. main.cpp : #include <set>
The following doesn't compile, but how can I get the equivalent functionality of [MYDIR]
The following doesn't compile public static T Retrieve<T>(this NameValueCollection collection, String key) where T
For some reason the following doesn't crash like my program does, but I'm pretty
The following code doesn't build. struct some_struct { some_struct() { ... do something here
The following code doesn't work (of course), because the marked line does not compile:
Can someone explain why the following doesn't work? int main() // Tried on several
The following doesn't compile: public void MyMethod<T>(T value) { if (value == default(T)) {
I have the following code but it doesn't seem to redirect to my action
Can someone explain why the following doesn't compile? I want that BB[A] is also

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.