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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T16:35:25+00:00 2026-05-16T16:35:25+00:00

I have a global multidimensional array, g_iAllData[MAX_LEN][MAX_WIDTH] being used in a Form. When I

  • 0

I have a global multidimensional array, g_iAllData[MAX_LEN][MAX_WIDTH] being used in a Form. When I write to it in a function: g_iAllData[iRow][iColumn]= iByte_Count; I can see in a Watch Window that it’s contents are not being changed. If I put the array in the function, it works fine.

Is there something I’m missing? I am declaring it as global after my #include‘s at the top of the Form1.h file. I have multiple functions that are called by buttons being pressed and I need to write and read from the array in each function. It would be easier to keep it as global instead of passing it to each function.

UPDATE code:

ProgramName.cpp

#include "stdafx.h"
#include "Form1.h"  

Form1.h

#include <iostream>
#include <string>
...
#pragma once  

const int MAX_LEN = 4033;
const int MAX_WIDTH = 21;
int g_iAllData[MAX_LEN][MAX_WIDTH];    
...
namespace ProgramName{
// later on
ReadFile();  

void ReadFile(void)

g_iAllData[iRow][iColumn]= iByte_Count;
  • 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-16T16:35:25+00:00Added an answer on May 16, 2026 at 4:35 pm

    Your code sample really confirms that you have a problem with your variable declaration.

    As @Graham hinted, the proper way to define globals is:

    • define the variable in a cpp file
    • declare the variable as extern in a header file

    I.e.

    //ProgramName.cpp
    
    #include "stdafx.h"
    #include "Form1.h"  
    
    int g_iAllData[MAX_LEN][MAX_WIDTH];    
    
    //Form1.h
    
    #include <iostream>
    #include <string>
    ...
    #pragma once  
    
    const int MAX_LEN = 4033;
    const int MAX_WIDTH = 21;
    extern int g_iAllData[MAX_LEN][MAX_WIDTH];    
    

    This way the linker will find the definition of the global variable in exactly one compilation unit, and in all other compilation units which #include the header, it will be able to link the extern declarations to the correct variable definition.

    Barring this, strange things may happen: you may get cryptic linker error messages complaining about multiple variable definitions, or you might even get multiple distinct variables in your app instead of one global variable – the latter explains why your method doesn’t seem to change the contents of your variable.

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

Sidebar

Related Questions

We have global lists in TFS that are used in custom fields on our
I have global static variables in a C library, which generate exceptions in a
In Actionscript you can have global variables like this: var number : Number =
Can Dynamic libraries have global, local and static variables in linux? If yes, then
If i have global variable in A.dll, that depends on global variable in B.dll
I have a global js file which has an ajax script. which is included
I have a global variable averagel that I am trying to manipulate in a
I have a global variable contacts, var contacts = ContactsApp.getContacts(); I have an KeyUphandler
I have a global header and footer that has a Database connection and a
I have a global pointer variable char* pointer = new char[500]; /* some operations...

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.