By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,372 Members | 1,511 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,372 IT Pros & Developers. It's quick & easy.

[survey] LWG issue 206

P: n/a
Hello,

I'm writing a brief paper on LWG issue 206:

http://www.open-std.org/jtc1/sc22/wg...ctive.html#206

It would help me immensely if I knew more about the current practice of
several vendors. I am asking for volunteers to post the results of the
following short program, along with the compiler (including version)
which produced those results. To get the ball rolling, here are results
I'm aware of:

CodeWarrior Pro 7-10:

custom allocation
custom deallocation
custom allocation
custom deallocation

gcc 4.0.1 on Mac OS X*:

custom allocation
custom deallocation
custom allocation
custom deallocation

* For the above results on gcc/Mac I had to add the following line to
the program which concerns a side issue I'm not addressing herein:

__attribute__((__weak__, __visibility__("default"))) int
dummy_weak_symbol_for_new;

Below is the test. Thank you in advance.

Howard Hinnant

----------------

#include <cstdio>
#include <cstdlib>
#include <new>

void* operator new(std::size_t size) throw(std::bad_alloc)
{
std::printf("custom allocation\n");
if (size == 0)
size = 1;
void*p = std::malloc(size);
if (p == 0)
throw std::bad_alloc();
return p;
}

void operator delete(void* ptr) throw()
{
std::printf("custom deallocation\n");
std::free(ptr);
}

int main()
{
int* i = new int;
delete i;
int* a = new int[3];
delete [] a;
}
Nov 10 '06 #1
Share this Question
Share on Google+
13 Replies


P: n/a
On Fri, 10 Nov 2006 19:31:05 GMT in comp.lang.c++, Howard Hinnant
<ho************@gmail.comwrote,
>I am asking for volunteers to post the results of the
following short program, along with the compiler (including version)
which produced those results.
C:\USR\temp>cl /EHsc h.cpp
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 13.10.3077 for
80x86
Copyright (C) Microsoft Corporation 1984-2002. All rights reserved.

h.cpp
Microsoft (R) Incremental Linker Version 7.10.3077
Copyright (C) Microsoft Corporation. All rights reserved.

/out:h.exe
h.obj

C:\USR\temp>h
custom allocation
custom deallocation
custom allocation
custom deallocation

Nov 10 '06 #2

P: n/a
On Fri, 10 Nov 2006 19:31:05 GMT in comp.lang.c++, Howard Hinnant
<ho************@gmail.comwrote,
>I am asking for volunteers to post the results of the
following short program, along with the compiler (including version)
which produced those results.
C:\USR\temp>dmc
Digital Mars Compiler Version 8.38n
Copyright (C) Digital Mars 2000-2003. All Rights Reserved.
Written by Walter Bright www.digitalmars.com

C:\USR\temp>dmc -Ae h.cpp
{
^
h.cpp(6) : Error: Exception specifications must match exactly for each
declaration of a function
{
^
h.cpp(17) : Error: Exception specifications must match exactly for each
declaration of a function
--- errorlevel 1

After changing those lines to respectively:
void* operator new(std::size_t size) // throw(std::bad_alloc)
void operator delete(void* ptr) // throw()

C:\USR\temp>dmc -Ae h.cpp
link h,,,user32+kernel32/noi;

C:\USR\temp>h
custom allocation
custom deallocation
custom deallocation
Nov 10 '06 #3

P: n/a
Howard Hinnant wrote:
Hello,

I'm writing a brief paper on LWG issue 206:

http://www.open-std.org/jtc1/sc22/wg...ctive.html#206

It would help me immensely if I knew more about the current practice of
several vendors. I am asking for volunteers to post the results of the
following short program, along with the compiler (including version)
which produced those results. To get the ball rolling, here are results
IBM VisualAge C++ 7.0 on AIX 5.3:

$ xlC qq.cpp
$ ./a.out
custom allocation
custom deallocation
HP ANSI C++ B3910B A.03.56 on HP-UX 11.11 (PARISC)

$ aCC -AA qq.cpp
$ ./a.out
custom allocation
custom deallocation
HP aC++/ANSI C B3910B A.06.00 [Aug 25 2004] on HP-UX 11.23 (Itanium)

$ aCC -AA qq.cpp && ./a.out
custom allocation
custom allocation
custom deallocation

Sun C++ 5.8 2005/10/13 on Solaris 8 (SPARC)

$ CC qq.cpp && ./a.out
custom allocation
custom allocation
custom allocation
custom allocation
custom allocation
custom allocation
custom allocation
custom allocation
custom allocation
custom allocation
custom allocation
custom allocation
custom allocation
custom allocation
custom allocation
custom allocation
custom allocation
custom allocation
custom allocation
custom allocation
custom deallocation
custom allocation
custom allocation
custom allocation
custom allocation
custom allocation
custom allocation
custom allocation
custom allocation
custom allocation
custom allocation
custom allocation
custom deallocation
custom allocation
custom deallocation
custom deallocation
custom deallocation
custom deallocation
custom deallocation
custom deallocation
custom deallocation
custom deallocation
custom deallocation
custom deallocation
custom deallocation
custom deallocation
custom deallocation
custom deallocation
custom deallocation
custom deallocation
custom deallocation
custom deallocation
custom deallocation
custom deallocation
custom deallocation
custom deallocation
custom deallocation
custom deallocation
custom deallocation
custom deallocation
custom deallocation
custom deallocation
custom deallocation
custom deallocation
custom allocation
custom allocation
custom deallocation
custom deallocation
custom deallocation
custom deallocation
custom deallocation
custom allocation
custom allocation
custom deallocation
custom deallocation
custom deallocation
custom deallocation
custom deallocation
custom allocation
custom allocation
custom deallocation
custom deallocation
custom deallocation
custom deallocation
custom deallocation
custom allocation
custom allocation
custom deallocation
custom deallocation
custom deallocation
custom deallocation
custom deallocation
custom allocation
custom allocation
custom deallocation
custom deallocation
custom deallocation
custom deallocation
custom deallocation
custom allocation
custom allocation
custom deallocation
custom deallocation
custom deallocation
GCC 4.0.2 on Solaris 8 (SPARC)
$ g++ qq.cpp && ./a.out
custom allocation
custom deallocation
custom allocation
custom deallocation

$ CC -V
CC: Forte Developer 7 C++ 5.4 2002/03/09 on Solaris 9 (SPARC)
$ CC qq.cpp && ./a.out
custom allocation
custom allocation
custom allocation
custom allocation
custom allocation
custom allocation
custom allocation
custom allocation
custom allocation
custom allocation
custom allocation
custom allocation
custom allocation
custom allocation
custom allocation
custom allocation
custom allocation
custom allocation
custom allocation
custom allocation
custom deallocation
custom allocation
custom allocation
custom allocation
custom allocation
custom allocation
custom allocation
custom allocation
custom allocation
custom allocation
custom allocation
custom allocation
custom deallocation
custom allocation
custom deallocation
custom deallocation
custom deallocation
custom deallocation
custom deallocation
custom deallocation
custom deallocation
custom deallocation
custom deallocation
custom deallocation
custom deallocation
custom deallocation
custom deallocation
custom deallocation
custom deallocation
custom deallocation
custom deallocation
GCC 3.4.3 on Solaris 9 (SPARC)

$ g++ qq.cpp && ./a.out
custom allocation
custom deallocation
custom allocation
custom deallocation

GCC 3.4.0 on RedHat Enterprise Linux AS release 3

$ g++ qq.cpp && ./a.out
custom allocation
custom deallocation
custom allocation
custom deallocation

Regards,
Alexey Sarytchev
Nov 10 '06 #4

P: n/a
In article <45***************@news.west.earthlink.net>, David Harmon
says...
On Fri, 10 Nov 2006 19:31:05 GMT in comp.lang.c++, Howard Hinnant
<ho************@gmail.comwrote,
I am asking for volunteers to post the results of the
following short program, along with the compiler (including version)
which produced those results.

C:\USR\temp>dmc
Digital Mars Compiler Version 8.38n
Copyright (C) Digital Mars 2000-2003. All Rights Reserved.
Written by Walter Bright www.digitalmars.com
g++ (GCC) 3.4.5 (mingw special)

custom allocation
custom deallocation
custom allocation
custom deallocation
Nov 10 '06 #5

P: n/a
On Fri, 10 Nov 2006 21:11:28 GMT in comp.lang.c++, Alexey Sarytchev
<al***@hotmail.comwrote,
>$ CC qq.cpp && ./a.out
custom allocation
custom allocation
custom allocation
custom allocation
custom allocation
custom allocation
custom allocation
custom allocation
custom allocation
custom allocation
custom allocation
custom allocation
custom allocation
....

Awesome. Perhaps you would add
cout << "Begin\n";
and
cout << "\End\n";
in main() for clarification.

Nov 10 '06 #6

P: n/a
In article
<ho**********************************@syrcnyrdrs-02-ge0.nyroc.rr.com>,
Howard Hinnant <ho************@gmail.comwrote:
Hello,

I'm writing a brief paper on LWG issue 206:

http://www.open-std.org/jtc1/sc22/wg...ctive.html#206

It would help me immensely if I knew more about the current practice of
several vendors.
Thanks to those who helped in the survey. If anyone has more data to
add (not already included in the paper), I will gladly accept it.

I've put the current draft of the paper up at:

http://home.twcny.rr.com/hinnant/cpp.../issue206.html

Comments, critiques on the paper are also welcome.

Thanks,
Howard
Nov 11 '06 #7

P: n/a
VJ
Howard Hinnant wrote:
>
CodeWarrior Pro 7-10:

custom allocation
custom deallocation
custom allocation
custom deallocation

gcc 4.0.1 on Mac OS X*:

custom allocation
custom deallocation
custom allocation
custom deallocation

* For the above results on gcc/Mac I had to add the following line to
the program which concerns a side issue I'm not addressing herein:

__attribute__((__weak__, __visibility__("default"))) int
dummy_weak_symbol_for_new;

Below is the test. Thank you in advance.

custom allocation
custom deallocation
custom allocation
custom deallocation

gcc version 4.0.2 20051125 (Red Hat 4.0.2-8)
Nov 13 '06 #8

P: n/a
David Harmon wrote:
On Fri, 10 Nov 2006 21:11:28 GMT in comp.lang.c++, Alexey Sarytchev
<al***@hotmail.comwrote,
>$ CC qq.cpp && ./a.out
custom allocation
custom allocation
custom allocation
custom allocation
custom allocation
custom allocation
custom allocation
custom allocation
custom allocation
custom allocation
custom allocation
custom allocation
custom allocation
...

Awesome. Perhaps you would add
cout << "Begin\n";
and
cout << "\End\n";
in main() for clarification.
$ CC -V
CC: Sun C++ 5.8 2005/10/13
$ CC qq.cpp && ./a.out
custom allocation
custom allocation
custom allocation
custom allocation
custom allocation
custom allocation
custom allocation
custom allocation
custom allocation
custom allocation
custom allocation
custom allocation
custom allocation
custom allocation
custom allocation
custom allocation
custom allocation
custom allocation
custom allocation
custom allocation
custom deallocation
custom allocation
custom allocation
custom allocation
custom allocation
custom allocation
custom allocation
custom allocation
custom allocation
custom allocation
custom allocation
custom allocation
Begin
custom allocation
custom deallocation
custom allocation
custom deallocation
End
custom deallocation
custom deallocation
custom deallocation
custom deallocation
custom deallocation
custom deallocation
custom deallocation
custom deallocation
custom deallocation
custom deallocation
custom deallocation
custom deallocation
custom deallocation
custom deallocation
custom deallocation
custom deallocation
custom deallocation
custom deallocation
custom deallocation
custom deallocation
custom deallocation
custom deallocation
custom deallocation
custom deallocation
custom deallocation
custom deallocation
custom deallocation
custom deallocation
custom deallocation
custom deallocation
custom allocation
custom allocation
custom deallocation
custom deallocation
custom deallocation
custom deallocation
custom deallocation
custom allocation
custom allocation
custom deallocation
custom deallocation
custom deallocation
custom deallocation
custom deallocation
custom allocation
custom allocation
custom deallocation
custom deallocation
custom deallocation
custom deallocation
custom deallocation
custom allocation
custom allocation
custom deallocation
custom deallocation
custom deallocation
custom deallocation
custom deallocation
custom allocation
custom allocation
custom deallocation
custom deallocation
custom deallocation
custom deallocation
custom deallocation
custom allocation
custom allocation
custom deallocation
custom deallocation
custom deallocation
$

for the next program:
================ cut =====================
#include <cstdio>
#include <cstdlib>
#include <new>
#include <iostream>
using namespace std;

void* operator new(std::size_t size) throw(std::bad_alloc)
{
std::printf("custom allocation\n");
if (size == 0)
size = 1;
void*p = std::malloc(size);
if (p == 0)
throw std::bad_alloc();
return p;
}

void operator delete(void* ptr) throw()
{
std::printf("custom deallocation\n");
std::free(ptr);
}

int main()
{
cout << "Begin\n";
int* i = new int;
delete i;
int* a = new int[3];
delete [] a;
cout << "End\n";
}
================ cut =====================

Regards,
Alexey Sarytchev
Nov 13 '06 #9

P: n/a
On Fri, 10 Nov 2006 20:34:30 GMT, David Harmon wrote:
>On Fri, 10 Nov 2006 19:31:05 GMT in comp.lang.c++, Howard Hinnant
wrote,
>>I am asking for volunteers to post the results of the
following short program, along with the compiler (including version)
which produced those results.

C:\USR\temp>dmc
Digital Mars Compiler Version 8.38n
Copyright (C) Digital Mars 2000-2003. All Rights Reserved.
Written by Walter Bright www.digitalmars.com

C:\USR\temp>dmc -Ae h.cpp
{
^
h.cpp(6) : Error: Exception specifications must match exactly for each
declaration of a function
{
^
h.cpp(17) : Error: Exception specifications must match exactly for each
declaration of a function
--- errorlevel 1

After changing those lines to respectively:
void* operator new(std::size_t size) // throw(std::bad_alloc)
void operator delete(void* ptr) // throw()
Why not just #include the necessary file?

Best wishes,
Roland Pibinger
Nov 13 '06 #10

P: n/a
Alexey Sarytchev wrote:
David Harmon wrote:
>On Fri, 10 Nov 2006 21:11:28 GMT in comp.lang.c++, Alexey Sarytchev
<al***@hotmail.comwrote,
>>$ CC qq.cpp && ./a.out
custom allocation
custom allocation
custom allocation
custom allocation
custom allocation
custom allocation
custom allocation
custom allocation
custom allocation
custom allocation
custom allocation
custom allocation
custom allocation
...

Awesome. Perhaps you would add
cout << "Begin\n";
and cout << "\End\n";
in main() for clarification.
I think you will like this:

$ aCC -V
aCC: HP aC++/ANSI C B3910B A.06.00 [Aug 25 2004]
$ aCC -AA qq.cpp && ./a.out
custom allocation
custom allocation
custom allocation
custom allocation
custom allocation
custom allocation
custom allocation
custom allocation
custom allocation
custom allocation
custom allocation
custom deallocation
custom allocation
custom allocation
Begin
custom allocation
custom deallocation
End

$ aCC -V
aCC: HP ANSI C++ B3910B A.03.56
$ aCC -AA qq.cpp && ./a.out
custom allocation
custom allocation
custom allocation
custom allocation
custom allocation
custom allocation
custom allocation
custom allocation
custom allocation
custom allocation
custom deallocation
custom allocation
custom allocation
Begin
custom allocation
custom deallocation
End
Regards,
Alexey Sarytchev
Nov 13 '06 #11

P: n/a
David Harmon <so****@netcom.comwrote:
On Fri, 10 Nov 2006 19:31:05 GMT in comp.lang.c++, Howard Hinnant
<ho************@gmail.comwrote,
>>I am asking for volunteers to post the results of the
following short program, along with the compiler (including version)
which produced those results.

C:\USR\temp>cl /EHsc h.cpp
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 13.10.3077 for
80x86

custom allocation
custom deallocation
custom allocation
custom deallocation
For what it's worth, I get the same results with

Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 13.10.6030 for 80x86

which is the Visual Studio .NET 2003 compiler with SP1 applied, and a
stricter set of compile options in terms of standards-compliance
(thought most of them shouldn't affect this example):
(cl /EHsc /Zc:forScope,wchar_t /GR /Za /Op- hh.cpp)

--
Marcus Kwok
Replace 'invalid' with 'net' to reply
Nov 13 '06 #12

P: n/a
In article <ej**********@news-int2.gatech.edu>,
ri******@gehennom.invalid (Marcus Kwok) wrote:
David Harmon <so****@netcom.comwrote:
On Fri, 10 Nov 2006 19:31:05 GMT in comp.lang.c++, Howard Hinnant
<ho************@gmail.comwrote,
>I am asking for volunteers to post the results of the
following short program, along with the compiler (including version)
which produced those results.
C:\USR\temp>cl /EHsc h.cpp
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 13.10.3077 for
80x86

custom allocation
custom deallocation
custom allocation
custom deallocation

For what it's worth, I get the same results with

Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 13.10.6030 for 80x86

which is the Visual Studio .NET 2003 compiler with SP1 applied, and a
stricter set of compile options in terms of standards-compliance
(thought most of them shouldn't affect this example):
(cl /EHsc /Zc:forScope,wchar_t /GR /Za /Op- hh.cpp)

Thanks, I've changed my reference to:

* Microsoft Visual Studio, all recent versions

http://home.twcny.rr.com/hinnant/cpp.../issue206.html

If anyone discovers this is not an accurate characterization, please
make some noise.

-Howard
Nov 13 '06 #13

P: n/a
On Mon, 13 Nov 2006 15:26:23 GMT in comp.lang.c++, rp*****@yahoo.com
(Roland Pibinger) wrote,
>>After changing those lines to respectively:
void* operator new(std::size_t size) // throw(std::bad_alloc)
void operator delete(void* ptr) // throw()

Why not just #include the necessary file?
Which file would that be?

Nov 13 '06 #14

This discussion thread is closed

Replies have been disabled for this discussion.