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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T02:17:55+00:00 2026-05-19T02:17:55+00:00

I know this is a question that every programmer should know, but I do

  • 0

I know this is a question that every programmer should know, but I do not know. Long time no C programming and I’ve forgotten a lot of things.

My question is:

I have three huge static arrays defined inside a header file. Someone told me that It’s much better to declare them as extern in the header file, and define them in a single C or C++ source file.

How can I do that?

Here is my header file:

#ifndef _TEMPLE_OBJECT_H_
#define _TEMPLE_OBJECT_H_


#define NUM_TEMPLE_OBJECT_VERTEX 10818

static const float TEMPLEVertices[NUM_TEMPLE_OBJECT_VERTEX * 3] = {...};
static const float TEMPLENormals[NUM_TEMPLE_OBJECT_VERTEX * 3] = {...};
static const float TEMPLETexCoords[NUM_TEMPLE_OBJECT_VERTEX * 3] = {...};

#endif

If a use a C++ source file, may I need to define a class?

UPDATE:
I think the problem is:
Every source file in which those headers are included (even indirectly) will generate its own definition for those static arrays. There’s no guarantee that the compiler/linker will optimize them into a single definition, even in source files where they’re unused. In fact, in many cases the compiler cannot optimize them away. This could result in your static data consuming a lot of disk space, and possibly runtime memory as well.

Thank you.

  • 1 1 Answer
  • 1 View
  • 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-05-19T02:17:56+00:00Added an answer on May 19, 2026 at 2:17 am

    static and extern at the same time makes no sense. static at file scope makes the array inaccessible by other files, while extern tells the compiler that your array is defined somewhere else.

    You can do what 321008 suggests, except that you don’t declare your arrays static which is illegal C and C++. That gives you three global variables that you can use wherever the header file is included.

    For example like this:

    // .h file:
    
    extern const float TEMPLEVertices[];
    
    // .cpp (or .c) file:
    
    const float TEMPLEVertices[] = { 1.0, 2.0, 5.6 /* or whatever*/ };
    

    Or you can do what fortran suggests, but that will give you file-scope access only, not global variables.

    You do not in any way have to define a class if you use a C++ source file. Unlike Java, C++ does not force you into an object oriented design (whether or not that is good can probably be discussed, but anyway).

    EDIT: As for your question update, that is because you define them as static. If you only want global variables, you should not do that, but instead keep one single definition (const float) and reference it with extern, as per my example above.

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

Sidebar

Related Questions

this is my first question here :) I know that I should not check
So I know this is a question that has been asked a lot, but
I know that this question is asked a lot, I checked all of the
I know this question is overly popular, but I find nothing that addresses rewriting
This is a question that I've always wanted to know the answer, but never
i didn't really know how to title this question, but here's a thing that
I know that this is a simple question for PHP guys but I don't
I know this is not a technical question, but this is something I believe
I know that this may seem as a question that was already asked, but
I know from this question that Firefox 3.0 and up stores its cookies in

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.