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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T12:59:05+00:00 2026-05-11T12:59:05+00:00

I am getting this error error: Access.Core may be used uninitialized in this function

  • 0

I am getting this error

error: Access.Core may be used uninitialized in this function 

And this is my code:

 static int FirstTime = 1;  MyStruct Access;   if (FirstTime) {    FirstTime = 0;    Access = Implementation();    DoSomething(Access);  }   if(Other_Variable) {     Access = Implementation2();     DoSomething(Access);   }    //The Other_Variable will be set to 1 and to 0 by other part of the code 

My code is like that because I want to call to the function Implementation only the first time. In every call the Access variable is going to be updated so it does not make many sense make it static.

If I make Access static works, but I do not like make it static because in every other call Access is going to be updated. Any way to avoid the problem without making it static?.

Also any better options to execute only once a function instead of using a static variable are welcome.

  • 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. 2026-05-11T12:59:06+00:00Added an answer on May 11, 2026 at 12:59 pm

    Make Access like this (and remove FirstTime and the if):

    static MyStruct Access = Implementation(this_b); 

    The reason you get this warning is because static variables survive one function call. Their value is retained across all function calls (without regard to which thread calls that function). So, FirstTime will control whether you initialize Access. The first time you call the function that code is in will correctly initialize the Access variable. But with every further function call, FirstTime is zero, and you will not initialize Access anymore, and thus will use an uninitialized variable down the code.

    Edit: Now, with your updated information, you say that you have two Implementation functions. The first time you want to use one, and all the other times you want to use another function. How about this then:

     // static will be false/zero by default  static bool AlreadyCalled;  MyStruct Access;   if (!AlreadyCalled) {    Access = Implementation();    AlreadyCalled = true;  } else {    Access = Implementation2();  } 

    Depending on your actual use case, there may be better ways to handle this, though. For example, why not update the state of Access, like this:

    // let the default constructor initialize it // to a plausible state static MyStruct Access;  // use RAII to update the state of Access when this // function returns.  MyUpdater updater(Access);  // now, do whatever the function does.  

    Something like this for MyUpdater:

    struct MyUpdater {     MyStruct &s;     MyUpdater(MyStruct &s):s(s) { }     ~MyUpdater() {         s.ChangeState();     } }; 

    That pattern is called RAII: You associate some useful action with the constructor and destructor of a locally allocated object.

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

Sidebar

Ask A Question

Stats

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

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

    • 7 Answers
  • Editorial Team

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

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Rather than dealing with adding N try/catch blocks to N… May 12, 2026 at 1:09 am
  • Editorial Team
    Editorial Team added an answer Internationalization is a seemingly simple, yet very complex feature to… May 12, 2026 at 1:09 am
  • Editorial Team
    Editorial Team added an answer Tom's answer is correct, but also take a look at… May 12, 2026 at 1:09 am

Related Questions

I'm trying to get Google AppEngine to work on my Debian box and am
I have an OSGi plugin with an activator that I am requesting to start
I have a .NET project that's always been built/run by/on 32 bit machines. I
I would like to make an ajax call to a different server (same domain

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.