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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T10:29:28+00:00 2026-05-31T10:29:28+00:00

I am writing a chess engine and to get pseudo-random moves, I pass a

  • 0

I am writing a chess engine and to get pseudo-random moves, I pass a move generation function an array to fill. Here is some code:

…

else if(pstrcmp(input, (char*)"check", 5)){
            int checkIndex = getIndex(input[6], input[7] - 49);
            printf("checkindex %i\n", checkIndex);
            if(!(checkIndex < 0 || checkIndex > 127)){
                //we've received a valid check
                struct m mUn[MOVE_BUFF];
                gen_psm(checkIndex, mUn);
                int i = 0;
                while(mUn[i].start != mUn[i].end && i < MOVE_BUFF){
                    printf("%s\n", GSQ(mUn[i].end));
                    i++;
                }
            }
        }

…

The first line is just some input checking. The meat of the code is between struct m mUn[MOVE_BUFF] and the while loop. So I create a struct m array, which I created and it holds a few ints that specifies a specific move, and then I pass it to gen_psm which takes an index of the square to check and an array to fill. It fills the array with valid moves for the piece located at the index. Fine and dandy for the first move. Then I try the second move, and I find that the array still has the data in it from the first move, even though I have long exited the scope of the mUn where I declared it. Is it some nature of structs that it retains its data? Do I need to 0 fill the whole thing (it seemed to be full of 0’s when I tried it). If I need to 0 fill it, is there a faster way (if I have to 0 fill it several 100 million times, that’s a problem)?

  • 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-31T10:29:29+00:00Added an answer on May 31, 2026 at 10:29 am

    There is nothing in the standard that guarantees that the memory of a local variable which has left scope will be changed, it is simply undefined behavior to read it. The compiler may zero it, it may not, it may insert a smiley into the beginning of it. It is unspecified as to what will happen to that memory location after the variable is out of scope.

    Simply declaring an array ensures that space will be reserved for it, but it does not initialize each member. You can memset it or just initialize each one in a loop.

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

Sidebar

Related Questions

Writing a function to generate and push some random data inside of the unknown
I am writing a simple chess-playing game. I won't post it all here, but
Writing some test scripts in IronPython, I want to verify whether a window is
Writing documentation in html requires some code examples. What to do with characters that
Writing some drag&drop code, I'd like to cancel the click events in my mouseup
Writing some classes for a Framework extension, and I have the following code: public
I'm writing a chess program with JQuery and I want to keep track of
Writing some regex to help process street addresses. However, I'm unsure if regex is
I'm writing a Othello engine using minimax with alpha-beta pruning. It's working ok, but
Writing a templated function, I declared: template <typename T> T invertible(T const& container, T::size_type

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.