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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:23:04+00:00 2026-05-27T20:23:04+00:00

Here is the code excerpt. std::map<double, double> temp; temp[0] = .1; cout << temp[1]

  • 0

Here is the code excerpt.

std::map<double, double> temp;

temp[0] = .1;

cout << temp[1] << endl;
// result varies based on compiler

I’m compiling using the GCC version 4.4.1 and I get a value of 0 from temp[1], as I expect. My co-worker is compiling on GCC version 4.5.1. In debug mode (with the -g flag), he gets 1000. When compiling release mode (-O2 flag), he gets 0.

My thought is that this is the type of issue that typically arises with uninitialized variables, except that maps are supposed to call the default constructor on their elements, based on this question and several others like it.

Moreover, The C++ Standard Library by Josuttis, states that

If you use a key as the index, for which no element yet exists, a new element gets
inserted into the map automatically. The value of the new element is
initialized by the default constructor of its type.

Why are elements in the map not being initialized in GCC 4.5.1 in debug mode? Am I not understanding what others have said about this behavior correctly? Is the default construction of new elements something that is not necessarily part of the standard? Or could this be an actual bug in the compiler?

  • 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-27T20:23:05+00:00Added an answer on May 27, 2026 at 8:23 pm

    As one would expect, the code excerpt is a simplified version of what’s really going on. It turns out that a find command is used on the map, so that essentially map.find(1)->second is being called, instead of simply map[1]. This explains the undefined behavior.

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

Sidebar

Related Questions

Here is a code excerpt from AspComet project that works with Autofac. public MessageBus(IClientRepository
What did I do wrong? Here is an excerpt from my code: public void
I'm writing some code that utilizes the boost filesystem library. Here is an excerpt
std::cout<<SendKeyBoardEvent <<keyBEventType<<endl; // Simulate a key press Sleep(200); //in if (!strcmp(keyBEventType,ENTER)) { // ENTER
Here is some code I wrote (using GCC's __restrict__ extension to C++): #include <iostream>
Here is a code excerpt from a dhtmlxgrid sample file: <p> You are allowed
Here's an example on JSFiddle . Excerpt of code: <table style=height:100%> <tr height=20><td></td></tr> <tr>
Ok the error is showing up somewhere in this here code if($error==false) { $query
Here is code from MSDN . I don't understand why the work isn't just
Here a code to demonstrate an annoying problem: class A { public: A(): m_b(1),

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.