473,386 Members | 1,702 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,386 software developers and data experts.

Three questions about lifetime and scope.

Consider the function with this prototype:

void foo(Bar bar);

1. Can a program call foo and allow only one addressable Bar object to exist
at a time?
Now consider the following program:

class Bar
{
int value;
public:
Bar() : value(0) { }
void change(int new_value) { value = new_value; }
};

void foo(Bar bar) { }

int main()
{
Bar bar;
bar.change(1);
foo(bar);
return 0;
}

2. Can this program be modified without change to foo and Bar so that:

i) main calls foo with the same value of bar, and
ii) only one addressable Bar object exists at a time.
3. What is the practical significance, if any, of the previous two questions
in relation to data sharing and copy-on-write?
Please support your answers with examples. Any help is appreciated.
Jul 22 '05 #1
11 1466
* Jason Heyes:
[homework questions]


Off-topic; see the FAQ on HOMEWORK QUESTIONS.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Jul 22 '05 #2
"Alf P. Steinbach" <al***@start.no> wrote in message
news:41*****************@news.individual.net...
* Jason Heyes:
[homework questions]


Off-topic; see the FAQ on HOMEWORK QUESTIONS.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?


How do I modify my post so that the forum doesn't interpret it as homework?
Jul 22 '05 #3
* Jason Heyes:
[quoting signature]
Do not quote signatures; corrected; see FAQs on how to post.
* Jason Heyes: * Alf P. Steinbach:
* Jason Heyes:
[homework questions]


Off-topic; see the FAQ on HOMEWORK QUESTIONS.


How do I modify my post so that the forum doesn't interpret it as homework?


You can't.

The question

3. What is the practical significance, if any, of the previous two
questions in relation to data sharing and copy-on-write?

is too strong evidence.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Jul 22 '05 #4
Jason Heyes wrote:

"Alf P. Steinbach" <al***@start.no> wrote in message
news:41*****************@news.individual.net...
* Jason Heyes:
[homework questions]


Off-topic; see the FAQ on HOMEWORK QUESTIONS.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?


How do I modify my post so that the forum doesn't interpret it as homework?

Eg. by telling us your point of view of what the answers could be and why.

--
Karl Heinz Buchegger
kb******@gascad.at
Jul 22 '05 #5
Jason Heyes wrote:

"Alf P. Steinbach" <al***@start.no> wrote in message
news:41*****************@news.individual.net...
* Jason Heyes:
[homework questions]


Off-topic; see the FAQ on HOMEWORK QUESTIONS.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?


How do I modify my post so that the forum doesn't interpret it as homework?

Homework per se is not the problem.
But what we don't do: Answer homework question when we see no sign in the posting
that the OP has made an attempt at solving the puzzle on his/her own.

Just posting the assignment doesn't qualify as 'making an attempt'

--
Karl Heinz Buchegger
kb******@gascad.at
Jul 22 '05 #6

"Alf P. Steinbach" <al***@start.no> wrote in message
news:41*****************@news.individual.net...
* Jason Heyes:
[quoting signature]
Do not quote signatures; corrected; see FAQs on how to post.
* Jason Heyes:
* Alf P. Steinbach:
* Jason Heyes:
> [homework questions]

Off-topic; see the FAQ on HOMEWORK QUESTIONS.


How do I modify my post so that the forum doesn't interpret it as

homework?
You can't.

The question

3. What is the practical significance, if any, of the previous two
questions in relation to data sharing and copy-on-write?

is too strong evidence.


I was just thinking. This guy seems to have cropped up just as another
poster with a similar personality disappeared by the name of JKop.

Jeff F
Jul 22 '05 #7
"Karl Heinz Buchegger" <kb******@gascad.at> wrote in message
news:41***************@gascad.at...
Jason Heyes wrote:

"Alf P. Steinbach" <al***@start.no> wrote in message
news:41*****************@news.individual.net...
>* Jason Heyes:
>> [homework questions]
>
> Off-topic; see the FAQ on HOMEWORK QUESTIONS.
>
> --
> A: Because it messes up the order in which people normally read text.
> Q: Why is it such a bad thing?
> A: Top-posting.
> Q: What is the most annoying thing on usenet and in e-mail?


How do I modify my post so that the forum doesn't interpret it as
homework?

Homework per se is not the problem.
But what we don't do: Answer homework question when we see no sign in the
posting
that the OP has made an attempt at solving the puzzle on his/her own.

Just posting the assignment doesn't qualify as 'making an attempt'


I don't see the point of making hopeless attempts at questions I need help
with.
Jul 22 '05 #8
"Karl Heinz Buchegger" <kb******@gascad.at> wrote in message
news:41***************@gascad.at...
Jason Heyes wrote:

"Alf P. Steinbach" <al***@start.no> wrote in message
news:41*****************@news.individual.net...
>* Jason Heyes:
>> [homework questions]
>
> Off-topic; see the FAQ on HOMEWORK QUESTIONS.
>
> --
> A: Because it messes up the order in which people normally read text.
> Q: Why is it such a bad thing?
> A: Top-posting.
> Q: What is the most annoying thing on usenet and in e-mail?


How do I modify my post so that the forum doesn't interpret it as
homework?

Eg. by telling us your point of view of what the answers could be and why.


I'd rather not speculate on what the answers to my own questions could be.
Thus the point of writing the question in the first place; that is, so you
guys can help me out!
Jul 22 '05 #9
Jason Heyes wrote:

Eg. by telling us your point of view of what the answers could be and why.


I'd rather not speculate on what the answers to my own questions could be.
Thus the point of writing the question in the first place; that is, so you
guys can help me out!


Tell us your speculation.
If it's correct, we let you know.
If it's not correct, we have something to work with.

In any case: The group is perfectly willing to discuss your thoughts.
What is correct on them, what is wrong on them.
But for this you need to tell us your thoughts.

--
Karl Heinz Buchegger
kb******@gascad.at
Jul 22 '05 #10
"Jason Heyes" <ja********@optusnet.com.au> wrote in message news:<41***********************@news.optusnet.com. au>...
Consider the function with this prototype:

void foo(Bar bar);

1. Can a program call foo and allow only one addressable Bar object to exist
at a time?
What do you think?
void foo(Bar bar) { }

int main()
{
Bar bar;
bar.change(1);
foo(bar);
return 0;
}

2. Can this program be modified without change to foo and Bar so that:

i) main calls foo with the same value of bar, and
ii) only one addressable Bar object exists at a time.
What do you think?


3. What is the practical significance, if any, of the previous two questions
in relation to data sharing and copy-on-write?


In order to answer your questions, I must know
what is addressable object and what is not?
Give just one example.
That would be a good start.

Greetings, Bane.
Jul 22 '05 #11
"Branimir Maksimovic" <bm***@volomp.com> wrote in message
news:88**************************@posting.google.c om...
"Jason Heyes" <ja********@optusnet.com.au> wrote in message
news:<41***********************@news.optusnet.com. au>...
Consider the function with this prototype:

void foo(Bar bar);

1. Can a program call foo and allow only one addressable Bar object to
exist
at a time?


What do you think?
void foo(Bar bar) { }

int main()
{
Bar bar;
bar.change(1);
foo(bar);
return 0;
}

2. Can this program be modified without change to foo and Bar so that:

i) main calls foo with the same value of bar, and
ii) only one addressable Bar object exists at a time.


What do you think?


3. What is the practical significance, if any, of the previous two
questions
in relation to data sharing and copy-on-write?


In order to answer your questions, I must know
what is addressable object and what is not?
Give just one example.
That would be a good start.


An l-value is an addressable object. An r-value is a non-addressable object.
Example:

Bar bar = Bar();

The object 'bar' is an l-value and so is addressable. The object Bar() is an
r-value and so is non-addressable.
Jul 22 '05 #12

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

Similar topics

1
by: Martin Ziebart | last post by:
Hi ! The following PHP-Code: >> $conn=pg_connect ($conn_string); >> $query=pg_exec ($conn, $sql_statement); // it's pg_query for PHP >4.2.0 >> pg_close ($conn);
6
by: Jason Heyes | last post by:
Consider the function with this prototype: void foo(Bar bar); 1. Can a program call foo and allow only one addressable Bar object to exist at a time? Now consider the following program:
15
by: copx | last post by:
Q1: If an array is declared static in file A is it still valid to access it from file B? I mean if a function form file A which returns a pointer to a position inside of the array is called from...
16
by: anonymous.user0 | last post by:
The way I understand it, if I have an object Listener that has registered as a listener for some event Event that's produced by an object Emitter, as long as Emitter is still allocated Listener...
14
by: Frederick Gotham | last post by:
There is a common misconception, (one which I myself also held at one point), that a const reference can "extend the lifetime of a temporary". Examples such as the following are given: Snippet...
23
by: TefJlives | last post by:
Hi all, I'm learning a bit about C, and I have a few questions. I'm not trying to insult C or anything with these questions, they're just honestly things I don't get. It seems like pointers...
9
by: David | last post by:
With a non-server app there is one instance of the program running and one user 'using' it at a time. With this scenario I'm pretty comfortable with variable scope and lifetime. With a server app...
16
by: Haskell Prelude | last post by:
Hello Friends - Can anyone answer these C questions? 1. What is the effect of making an internal (local) variable static? 2. What is the effect of making an external (non-local) variable...
5
by: somenath | last post by:
Hi All , I have one question regarding scope and lifetime of variable. #include <stdio.h> int main(int argc, char *argv) { int *intp = NULL; char *sptr = NULL;
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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...

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.