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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T11:26:23+00:00 2026-05-13T11:26:23+00:00

I have a character array defined in a header //header.h const char* temp[] =

  • 0

I have a character array defined in a header

//header.h
const char* temp[] = {"JeffSter"};

The header if #defined guarded and has a #pragma once at the top. If this header is included in multiple places, I get an LNK4006 – char const * * temp already defined in blahblah.obj. So, I have a couple of questions about this

  1. Why does this happen if I have the guards in place? I thought that they prevented the header from being read in after the first access.
  2. Why do the numerous enums in this header not also give the LNK4006 warnings?
  3. If I add static before the signature, I don’t get the warning. What are the implications of doing it this way.
  4. Is there a better way to do this that avoids the error, but lets me declare the array in the header. I would really hate to have a cpp file just for an array definition.
  • 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-05-13T11:26:23+00:00Added an answer on May 13, 2026 at 11:26 am

    Why does this happen if I have the guards in place? I thought that they prevented the header from being read in after the first access.

    Include guards make sure that a header is included only once in one file (translation unit). For multiple files including the header, you want the header to be included in each file.

    By defining, as opposed to declaring variables with external linkage (global variables) in your header file, you can only include the header in once source file. If you include the header in multiple source files, there will be multiple definitions of a variable, which is not allowed in C++.

    So, as you have found out, it is a bad idea to define variables in a header file for precisely the reason above.

    Why do the numerous enums in this header not also give the LNK4006 warnings?

    Because, they don’t define “global variables”, they’re only declarations about types, etc. They don’t reserve any storage.

    If I add static before the signature, I don’t get the warning. What are the implications of doing it this way.

    When you make a variable static, it has static scope. The object is not visible outside of the translation unit (file) in which it is defined. So, in simple terms, if you have:

    static int i;
    

    in your header, each source file in which you include the header will get a separate int variable i, which is invisible outside of the source file. This is known as internal linkage.

    Is there a better way to do this that avoids the error, but lets me declare the array in the header. I would really hate to have a cpp file just for an array definition.

    If you want the array to be one object visible from all your C++ files, you should do:

    extern int array[SIZE];
    

    in your header file, and then include the header file in all the C++ source files that need the variable array. In one of the source (.cpp) files, you need to define array:

    int array[SIZE];
    

    You should include the header in the above source file as well, to allow for catching mistakes due to a difference in the header and the source file.

    Basically, extern tells the compiler that “array is defined somewhere, and has the type int, and size SIZE“. Then, you actually define array only once. At link stage, everything resolves nicely.

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

Sidebar

Ask A Question

Stats

  • Questions 294k
  • Answers 294k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You need to understand how Unicode works to build a… May 13, 2026 at 6:39 pm
  • Editorial Team
    Editorial Team added an answer You may want to consider whether the approach you are… May 13, 2026 at 6:39 pm
  • Editorial Team
    Editorial Team added an answer Are you sure the directory that libbebop_util.so is in is… May 13, 2026 at 6:39 pm

Related Questions

Okay so i have a packed a proprietary binary format. That is basically a
I have a closed source unmanaged DLL coded in C++ that I wanted to
I am working with an open-source UNIX tool that is implemented in C++, and
I'm having to modify some client side code because the comms protocol wasn't defined
I am having some trouble provding a Win32 tooltips control with dynamic text in

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.