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

  • Home
  • SEARCH
  • 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 8992149
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T22:53:17+00:00 2026-06-15T22:53:17+00:00

In my program, I have a file called constants.h that declares the following matrix

  • 0

In my program, I have a file called constants.h that declares the following matrix in a global scope (the matrix should be fully constant – if anyone sees a potential problem, let me know):

static unsigned char const MY_MATRIX[66][9] = {...};

In another file, let’s call it main.c, I can actually reference this constant:

doSomething(var1, count, MY_MATRIX[42], TRUE, FALSE, thing);

But then I just read the definition of the keyword static and it’s supposed to mean that the variable cannot be accessed outside the file it’s defined in. (In this case, the desired behavior is that it should be accessed, but then it seems the extern keyword is the one to use!)

So, can anyone tell me why this works? Why is the variable not invisible? Thanks!

  • 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-15T22:53:19+00:00Added an answer on June 15, 2026 at 10:53 pm

    This is because you are declaring a static variable in a header: when you include the header in a C file, you get a brand-new definition independent of the other definitions. If you include the header in two files, you get two independent copies; if you include it in three C files, you get three independent copies, and so on. The copies do not conflict with each other, because the static definition hides them from the linker.

    A proper way to make use of a shared piece of data allocated in a static memory is to make the declaration extern in the header, and then add a non-static definition in exactly one C file.

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

Sidebar

Related Questions

I have a program that creates a module called cool using file operations. I
I have a file transfer program. The program (Client) does following operations to send
I have a program that reads from a file that grabs 4 bytes from
I have a program that reads data from a file line-by-line. I would like
I have a program that generates a .shp file, and exports this as a
I have a program that creates a small file in the Bin directory for
I have set up a JUnit test that is testing a method called copy(File
So I have a program that runs something like the following public class SHandler
I have a program that progresses as follows. I call a method called getCharacteristics
My multithread program crash. I have .core file. I load it and thread apply

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.