f



Static instances of std::map allowed by C++ standard?

I am curious if the C++ Standard (14882:1998(E) ) actually disallows
static instances of std::map as in:

#include <map>
std::map<int, int> foo;
int main() { return 0; }

When I use the Microsoft Visual Studio .NET 2003 compiler with some
code that uses static instances of maps, Rational Purify reports:

UMR: Uninitialized memory read in std::_Tree_nod

and tracing through the stack it seems associated with the allocator
initialization for std::map.  Moreover when I replace the static map
instances with a Singleton pattern, Purify reports no errors.

The problem doesn't seem 100% consistent; for example, the 3-line
program above does _not_ seem to trigger the Rational Purify problem.

If static map instances are indeed forbidden, this would seem somewhat
invasive; for example, it would imply that CppUnit test fixture classes
can't contain any std::map data members (since static instances of
these classes are declared by the fixture registration macro).
Thanks in advance,
Jordan Samuels


      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]
0
jordan59 (4)
12/23/2004 10:13:06 PM
comp.lang.c++.moderated 10738 articles. 1 followers. allnor (8510) is leader. Post Follow

5 Replies
648 Views

Similar Articles

[PageSpeed] 19

On 23 Dec 2004 17:13:06 -0500, <jordan@madsam.com> wrote:

> I am curious if the C++ Standard (14882:1998(E) ) actually disallows
> static instances of std::map as in:
>
> #include <map>
> std::map<int, int> foo;
> int main() { return 0; }
>
> When I use the Microsoft Visual Studio .NET 2003 compiler with some
> code that uses static instances of maps, Rational Purify reports:

[]

AFAIK, the standard does not disallow that.

<slightly offtopic>

There is a little problem with standard containers in a dll.

DllMain() docs for windoze clearly state that it is not safe to use
new/delete before and during DllMain(). The stadard allocator uses
::operator new/delete. So, to be on the safe side one might want to use
static instances of standard containers in a dll with a custom allocator,
that does not use ::operator new/delete, rather something like
HeapAlloc/HeapFree(GetProcessHeap(), ...).

-- 
Maxim Yegorushkin

      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]
0
Maxim
12/24/2004 9:47:18 AM
<jordan@madsam.com> wrote in message
news:1103823663.239539.245430@z14g2000cwz.googlegroups.com...

>I am curious if the C++ Standard (14882:1998(E) ) actually disallows
> static instances of std::map as in:
>
> #include <map>
> std::map<int, int> foo;
> int main() { return 0; }

No, they're permitted.

> When I use the Microsoft Visual Studio .NET 2003 compiler with some
> code that uses static instances of maps, Rational Purify reports:
>
> UMR: Uninitialized memory read in std::_Tree_nod
>
> and tracing through the stack it seems associated with the allocator
> initialization for std::map.  Moreover when I replace the static map
> instances with a Singleton pattern, Purify reports no errors.

It's probably a known bug in Purify. Default allocators are
zero-size objects which, under some circumstances, must be
made nonzero-size by adding one or more padding bytes.
Purify gets bent out of shape by attempts to copy the padding
bytes, at least under some circumstances.

P.J. Plauger
Dinkumware, Ltd.
http://www.dinkumware.com



      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]
0
P
12/24/2004 9:54:23 AM
> I am curious if the C++ Standard (14882:1998(E) ) actually disallows
> static instances of std::map as in:

There is no such prohibition.  It's a bug in the implementation or
more than likely a false positive by purify.


      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]
0
James
12/24/2004 10:17:48 AM
"Maxim Yegorushkin" <e-maxim@yandex.ru> wrote in message
news:opsjh7zcsbti5cme@devlx007.ipcb.net...
> On 23 Dec 2004 17:13:06 -0500, <jordan@madsam.com> wrote:
>
> DllMain() docs for windoze clearly state that it is not safe to
use
> new/delete before and during DllMain().

Where does it say this?

Yechezkel Mett



      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]

0
Yechezkel
12/29/2004 9:08:45 PM
{PLease take any further followups to private email as this is OT for 
clc++m -mod}

On 29 Dec 2004 16:08:45 -0500, Yechezkel Mett <yechezkel@emailaccount.com>
wrote:

>> DllMain() docs for windoze clearly state that it is not safe to
> use
>> new/delete before and during DllMain().
>
> Where does it say this?

Well, I could not find it in the current DllMain() docs, but I seem to
remember it was there, though I'm no longer sure.

-- 
Maxim Yegorushkin

      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]
0
Maxim
12/30/2004 9:53:14 AM
Reply:

Similar Artilces:

jython and C-c C-c
How do I get C-c C-c to work with jython? I have the jpython command set to jython, and I can start the interpreter with C-C ! and then use C-c C-c, but this is rather frustrating. If I try to use C-c C-c without first starting the interpreter in another window I get wrong type argument: sequencep, jpython Thanks, Dave Cook ...

Better C/C++ Than C/C++?
I am looking for a good systems programming language that can be used instead of C/C++. My qualifications for the language are: * mature compiler(s) that produce native-code binaries (for Windows) * open source - preferable, but not 100% necessary Thanks, Kevin "Kevin Albrecht" <kevin@albrecht.net> writes: > I am looking for a good systems programming language > that can be used instead of C/C++. My qualifications > for the language are: > > * mature compiler(s) that produce native-code > binaries (for Windows) Ocaml, D, cyclone, Eiffel, Beta >...

Why are static member variables allowed in c++ and not in C?
Hi All, I have seen this question(mentioned in subject) posted in various forums but some how I am not statisfied with the answer. 1- Is this because of where static variables are placed in c and c++ 2- or There is a constraint from the language(C) (didn't understand this much) and also related to this any links where I can find differences in c and c++ not related to language ie not like c++ has class and c has not but like const has external linkage in c but in c++ it has external linkage. Thanks, Manas -- [ See http://www.gotw.ca/resources/clcm.htm for ...

C/C++ in matlab and matlab in C/C++ ?
Is it possible to read C/C++ code in matlab and the other way around too? Hi, as long as C or C++ are written in text files you can edit them in the matlab editor. To see the special character of C or C++ coding language, in the editor go to menus: file>preferences>Edito/Debugger>language and on popup "Language" select "C/C++". This does not allow you to run the C/C++ code, just to view it i nicer way... regards, chris saneman <asdfsdf@asd.com> wrote in message <frl846 $f8i$2@news.net.uni-c.dk>... > Is it possible to read C/C...

C/C++ in MATALB or MATLAB in C/C++?
Hi I've been asking on the net how to use MEX properly so that I can use C/C++ in MATLAB, but information is not forthcoming. There seems to be a lot on using MATLAB in C/C++ but not the other way around. I understand Mathworks is trying very hard to sell the Matlab Compiler, but even so, why is it SO hard to get information about MEX? Or is it that I've missed something very fundamental, meaning that I'm struggling over something that is actually quite easy? Any thoughts and info would be great. Thanks BullDog BullDog wrote: > Hi > > I've been asking on the net ...

C as a Subset of C++ (or C++ as a superset of C)
Isn't it a lame use of human time and effort to maintain completely separate C and C++ standards? As in the words of Betty White about Facebook: "It seems like an incredible waste of time". Why don't the two standards groups get together and agree on a common specification for the ground which both standards cover? There would still be two separate standards, but they'd both be exactly the same for the common ground. The common ground document could be referred to by both standards instead of being maintained by both groups in individual efforts resulting in...

c------->c++ and c++------>c
We can write c program in turbo c++ editor.But reverse is not true why? i.e The program will not compile if u write c++ program in turbo c editor vim wrote: > We can write c program in turbo c++ editor.But reverse is not true why? > i.e The program will not compile if u write c++ program in turbo c > editor This isn't about C; this is about some editor. Why the fircone should /we/ know? Ask in a relevant group. [And /why/, in an editor specialised to some specific programming languages, would you expect it to compile a /different/ one? Would you expect turbo perl to compi...

slime C-c C-c annoyance
Does anyone have a good workaround for this problem other than: just be careful! When I've compiled a large package and slime has given me a *slime-compilation* buffer, I like to work through this buffer issue by issue, fixing the errors, warnings, etc. But If I ever press C-c C-c in the editor window while fixing an error, slime destroys the *(slime-compilation* buffer with the compilation output of C-c C-c. Jim Newton <jimka.issy@gmail.com> writes: > Does anyone have a good workaround for this problem other than: just be careful! > > When I've compiled a ...

how to allow large static space allocation in c/c++?
This is a multi-part message in MIME format. ------=_NextPart_000_0441_01C3BE41.0EB17B50 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable I am doing a experiment on solaris, in which I have to allocate a big = CONSECUTIVE memory space, I do it like this: int x[1000][1000], y[1000][1000], z[1000][1000]; just three big arrays, but after I compile and run this program, I was = told "segmentation error",=20 of course this could be solve by using "new" or having smaller = size(800x800 is ok), but since I want memory space ...

C,, C++, Java, C#
I come from C,C++,Java and C#. What can SmallTalk do for me and for what cost? Regarding the Squeak thing, it's interesting though confusing. Is it an IDE? Why are the menus so wacky? "DM McGowan II" <nospam@nospam.net> wrote in message news:PLednX2vnLd11IncRVn-rA@comcast.com... > I come from C,C++,Java and C#. What can SmallTalk do for me ...? Ask not what Smalltalk can do for, but what can you do with Smalltalk. :-) In very few words, it significantly reduces time to market, while enhancig the development experience. This is because: 1. It...

c,c++,obj-c
Of the 3 languages titled in this post is c++ older than obj-c ? Would someone experienced in C be able to dive right into C++ rather than obj-c ? Java is out for me now except applet programming I think I'm going to go with just C and C++. Bill Bill Cunningham wrote: > Of the 3 languages titled in this post is c++ older than obj-c ? Why does that matter? Do you want to use an old language? Try Fortran or LISP. > Would > someone experienced in C be able to dive right into C++ rather than > obj-c ? Not quite dive in, at least not into the OO parts of C++. ...

C, C++ and C# Forums
Throne Software has opened up C, C++ and C# Forums at: http://www.thronesoftware.com/forum/ Join us! Throne Software wrote: > Throne Software has opened up C, C++ and C# Forums at: > > http://www.thronesoftware.com/forum/ For all of your forums newsgroups already exist. > Join us! Why? Don't see any reason to support your marketing. ...

C, C++ and C# Forums
Throne Software has opened up C, C++ and C# Forums at: http://www.thronesoftware.com/forum/ Join us! ...

C, C++ and C# Forums
Throne Software has opened up C, C++ and C# Forums at: http://www.thronesoftware.com/forum/ Join us! In article <1120963701.862698.160260@g14g2000cwa.googlegroups.com>, Throne Software <mail@thronesoftware.com> writes >Throne Software has opened up C, C++ and C# Forums at: > >http://www.thronesoftware.com/forum/ > >Join us! Why? The beauty of news groups is that they come to me I don't have to go to them. Also all the people who have been around a while know what they are doing and are here. I noticed that there are some C and C++ Forums on another system...

Web resources about - Static instances of std::map allowed by C++ standard? - comp.lang.c++.moderated

Tribunal de grande instance de Paris - Wikipedia, the free encyclopedia
TGI is found in the Palace of Justice on the Île de la Cité along with Court of Appeal of Paris and Court of Cassation . This site (formerly ...

Facebook At SXSW: More Than 1 Billion Instances Of App Activity Shared Daily
More than 1 billion instances of application activity are shared via Facebook on a daily basis, and a total of more than 400 billion open graph ...

Changed the AWS instance size on the Trex server from small to large, and now it runs much better. ;-) ...
... piece. The one that made the big difference came from my longtime programming friend Chuck Shotton. We increased the size of the AWS instance ...

The Instance - Podcast App on the App Store on iTunes
Get The Instance - Podcast App on the App Store. See screenshots and ratings, and read customer reviews.

An instance of the fingerpost - Flickr - Photo Sharing!
Quite literally a fingerpost. Pelsall, Walsall, West Midlands. I had to drive past it to get to a meeting today. Great isn't it?

Buzzfeed Cans Editor After Uncovering '40 Instances' Of Plagiarism
... Editor-In-Chief Ben Smith announced his decision to fire the site’s “viral politics” writer Benny Johnson after finding at least “40 instances” ...

ACORN website allows Canberrans to report growing instances of cybercrime
A new website to fight cybercrime is set to save police an enormous amount of time and money.

Abbott's shift on settlements one more instance of secrecy
At least the Abbott government is doing its bit for the reading skills of journalists within Australia. Since there are fewer news conferences, ...

ACORN website allows Australians to report growing instances of cybercrime
A new website to fight cybercrime is set to save police an enormous amount of time and money.

Queensland Police are investigating several instances of looting in Bundaberg and Gympie
POLICE are investigating several instances of looting in Gympie and Bundaberg in the wake of flooding.

Resources last updated: 1/24/2016 3:41:54 PM