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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T13:28:08+00:00 2026-06-11T13:28:08+00:00

I used STL list in my win32 program, which run into a weird problem.

  • 0

I used STL list in my win32 program, which run into a weird problem. To be specific, I got an out of range runtime error on the first time the list did a push_back().

Here’s the declaration of this list instance:

AtomActionList g_AtomActions[MAXPLAYER];

It’s a global variable and in the same file with _tWinMain() entry.

Here’s the related defines (they are separated in 3 different header files):

#define MAXPLAYER 2

typedef int AtomAction_id;

typedef std::list<AtomAction_id> AtomActionList;

And here’s the parts that ever use g_AtomActions in the main file:

...

g_AtomActions[_i].push_back(aaid);

...

if (!g_AtomActions[_i].empty()){
    shareData.newAtomAction[_i] = g_AtomActions[_i].front();
    g_AtomActions[_i].pop_front();
}

There used to be a clear method in an init function but I commented it out when I saw the runtime “out of range” error in the g_AtomActions[_i].push_back(aaid); part. However, the error remains after that.

I’ve set some breakpoints and run it in debug mode and watch. I’m quite sure the error happens in the first time g_AtomActions[_i].push_back(aaid); is executed. _i is 0 and aaid is 2, size of g_AtomActions[_i] is 0. No other parts have ever used this identifier yet.

I failed to figure out why. So I tried to change it to deque, hoped to get some luck, and unexpectedly found the g_AtomActions[_i].push_back(aaid); works in my program (but errored again in another part which used list).

Could someone give a possible explanation?

  • 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-06-11T13:28:10+00:00Added an answer on June 11, 2026 at 1:28 pm

    Thanks to hints from @AlfP, this problem is finally resolved by me.

    Global variables are very bad. Some classes failed to initialize but never telled me anything until I use pointers to new them in another init function.

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

Sidebar

Related Questions

Possible Duplicate: Which sorting algorithm is used by STL’s list::sort()? Which sorting algorithm can
I got a strange problem while used luabind to return a stl::vector::iterator to lua
Using GCC 4.x, g++ and STL. Which internal structure should be used to hold
I frequently use the STL containers but have never used the STL algorithms that
I've created a small tool which is used to process binary files. All the
I'm using an STL std::multiset<> as a sorted list of pointers. The sort order
Note: I accidentally posted this question without specifying which STL implementation I was using,
I ran into some trouble while using a list of arrays. So to clear
I can't dump STL strings with WinDbg anymore - I used to be able
I have implemented a custom allocator (to be used by STL containers within my

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.