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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T00:00:58+00:00 2026-06-11T00:00:58+00:00

Well, reading a bit old book (The C programming language, second edition, by Dennis

  • 0

Well, reading “a bit old” book (“The C programming language”, second edition, by Dennis Ritchie), I came a cross the following:

An external variable must be defined, exactly once, outside of any function; this sets aside storage for it. The variable must also be declared in each function that wants to access it

and I was like – what?!

“The variable must also be declared in each function that wants to access it”. Then, I was shocked one more time:

int max; 
/* ... */
int main()
{
    extern int max;
    /* ... */
}

And one more – what?!


As far as I know (obviously, it’s not much and far from enough), extern makes sense only when you define a global variable somewhere and you want to access it through another file (not to define it again).

So:

  • What’s the point of this extern int max inside the main or any other function?
  • Does the standard really says, that this is a must (that I need to declare, for this example, this max in each function, that will use it?)
  • Is this the same for C++ (that’s why I placed the C++ tag)? This is the first time I see something like this.

Note: this is not the same as What is the use of declaring a static variable as extern inside a function?

  • 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-11T00:00:59+00:00Added an answer on June 11, 2026 at 12:00 am

    Your post surprised me. I had no recollection of that and I’ve read K&R long ago. I only have the first edition here and it is there too. However, that is not all it says. From the first edition:

    The variable must also be declared in each function that wants to
    access it; this may be done either by an explicit extern declaration
    or implicitly by context.

    Note the “implicitly by context.” Later in the text:

    …if the external definition of a variable occurs in the source file
    before its use in a particular function, then there is no need for an
    extern declaration in the function. The extern declarations in main,
    … are thus redundant. In fact, common practice is to place
    definitions of all external variables at the beginning of the source
    file, and then omit all extern declarations.

    So this is saying that making the extern variable visible can be done inside the function for just that function, or can be done outside any function for all functions following it in the source file. I believe that this is the only place in the book where it is done inside the function, later it uses the familiar once for the file approach.

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

Sidebar

Related Questions

After searching and reading a little bit I came up with the following SQL
Well I was reading this post and then I came across a code which
reading excel files from C# working well in 32 bit version server. It is
I just started diving into the world of Rails by reading the well known
I was reading about this person's interview at a well-known search company. http://asserttrue.blogspot.com/2009/05/one-of-toughest-job-interview-questions.html He
I was reading about pallet here: http://twoguysarguing.wordpress.com/2010/11/01/starting-a-cluster-on-ec2-with-pallet/ , as well as on the pallet
I was reading this link , and noticed this bit at the bottom: You
I'm reading Understanding Linux Kernel. Paging for 64-bit Architectures As we have seen in
at work I am struggling a bit with the following situation: We have a
I am reading a C book that deals a lot with asm and looking

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.