473,396 Members | 1,836 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

When is an unnamed automatic variable destroyed?

In this code, when will (should) Xfromer::release be called?
struct C {
C(const char* c) { f = Xformer::xform(c); }
~C() { Xformer::release(f); }
const F* get() const { return f; }
F* f;
};

void fun(const char* c) {
F* foo = C(c).get();
bar(foo);
baz();
}

--
NOUN:1. Money or property bequeathed to another by will. 2. Something handed
down from an ancestor or a predecessor or from the past: a legacy of
religious freedom. ETYMOLOGY: MidE legacie, office of a deputy, from OF,
from ML legatia, from L legare, to depute, bequeath. www.bartleby.com/61/
Mar 7 '06 #1
3 2240
Steven T. Hatton wrote:
In this code, when will (should) Xfromer::release be called?
struct C {
C(const char* c) { f = Xformer::xform(c); }
~C() { Xformer::release(f); }
const F* get() const { return f; }
F* f;
};

void fun(const char* c) {
F* foo = C(c).get();
The temporary that is used in the expression to initialise 'foo' will be
destroyed at the end of 'foo's initialisation. 'Xformer::release' should
be called as part of the destruction of the temporary, right after 'foo'
is initialised.
bar(foo);
baz();
}


V
--
Please remove capital As from my address when replying by mail
Mar 7 '06 #2
Victor Bazarov wrote:
Steven T. Hatton wrote:
In this code, when will (should) Xfromer::release be called?
struct C {
C(const char* c) { f = Xformer::xform(c); }
~C() { Xformer::release(f); }
const F* get() const { return f; }
F* f;
};

void fun(const char* c) {
F* foo = C(c).get();


The temporary that is used in the expression to initialise 'foo' will be
destroyed at the end of 'foo's initialisation. 'Xformer::release' should
be called as part of the destruction of the temporary, right after 'foo'
is initialised.
bar(foo);
baz();
}


V


http://tinyurl.com/oz2m6
http://koolkat2.cs.rice.edu/cgi-bin/...OMDocument.cpp
--
NOUN:1. Money or property bequeathed to another by will. 2. Something handed
down from an ancestor or a predecessor or from the past: a legacy of
religious freedom. ETYMOLOGY: MidE legacie, office of a deputy, from OF,
from ML legatia, from L legare, to depute, bequeath. www.bartleby.com/61/
Mar 7 '06 #3
Steven T. Hatton wrote:
Victor Bazarov wrote:

Steven T. Hatton wrote:
In this code, when will (should) Xfromer::release be called?
[...]


The temporary that is used [...]

V

http://tinyurl.com/oz2m6
http://koolkat2.cs.rice.edu/cgi-bin/...OMDocument.cpp


Uh... Did you mean to supply some explanation to those links?
Mar 7 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Anthony | last post by:
Hello, I have been reading up on unnamed namespaces in the context of hiding classes as mentionned by the GOF Facade pattern description. I was hoping someone could shed some light on this. I...
5
by: Matthias Kaeppler | last post by:
Hi, say I have a class X, such that: class X { A a; B b; C c; ...
3
by: Sandy | last post by:
Hi, I have two files as folllows file1.cpp #include<iostream> using namespace std; namespace { void show(); void fun() { cout<<"fun called\n"; } }
7
by: Eric Laberge | last post by:
Aloha! This question is meant to be about C99 and unnamed compound objects. As I read, if such a construct as int *p = (int){0}; is used within a function, then it has "automatic storage...
9
by: Simon | last post by:
Hi, I have written an ActiveX object to resize images and upload them to a database, this all works fine but when I close internet explorer the process iexporer.exe is still running in my task...
13
by: Kantha | last post by:
Hi all, I have declared an Union as follows typedef union { struct interrupt_bits { unsigned char c_int_hs_fs_status : 1, c_setup_intflag : 1,
9
by: Tom Plunket | last post by:
The project I'm currently on makes heavy use of unnamed structures to represent an "object hierarchy" of a sort. E.g. struct BaseObject { int aMember; int anotherMember; // etc.
58
by: Jorge Peixoto de Morais Neto | last post by:
I was reading the code of FFmpeg and it seems that they use malloc just too much. The problems and dangers of malloc are widely known. Malloc also has some overhead (although I don't know what is...
3
by: CrazyJohn | last post by:
Hi guys, This is my first time posting question here, if I break any rules, please kindly point out. And I'm really glad to be a part of this community. Here is my question, Our lecturer...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.