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

Tasking C166 C++ compiler & temporary objects in function call parameters

Somebody told me that Tasking C166 C++ compiler has problems with
temporary objects in function call parameters. He gave me below
examples:

Case 1:Wrong:
rc = foo(&bar());

Case 2:Right:
bar b;
rc=foo(&b);

But he didn't know why...Can anyone show me why? why case 1 is wrong
with Tasking C166 C++ compiler? How about other C++ compilers?

Thanks and Best Regards,
PerduBug

Jul 25 '06 #1
2 2378
pe******@gmail.com wrote:
Somebody told me that Tasking C166 C++ compiler has problems with
temporary objects in function call parameters. He gave me below
examples:

Case 1:Wrong:
rc = foo(&bar());

Case 2:Right:
bar b;
rc=foo(&b);

But he didn't know why...Can anyone show me why? why case 1 is wrong
with Tasking C166 C++ compiler? How about other C++ compilers?
...
The problem with the above code has nothing to do with any function call
parameters at all. In the first case you are trying to apply the built-in
operator '&' to a temporary object - '&bar()'. Built-in operator '&' cannot be
applied to temporary objects, because '&' requires an lvalue. Temporary objects
are not lvalues. That's it.

You can rewrite your code as follows

1.
&bar();

2. bar b;
&b;

and get the same problem without any function calls.

--
Best regards,
Andrey Tarasevich
Jul 25 '06 #2
Perdubug posted:
Somebody told me that Tasking C166 C++ compiler has problems with
temporary objects in function call parameters. He gave me below
examples:

Case 1:Wrong:
rc = foo(&bar());

You can't take the address of an R-value.

Case 2:Right:
bar b;
rc=foo(&b);

If you only need a const temporary, then:

class Arb {};

void Func(Arb const *) {}

int main()
{
Func(&static_cast<Arb const&>(Arb()));
}

If you need a non-const temporary, then perhaps try something like the
following:

template<class T>
struct Temp {

T obj;

Temp() : obj() {}

T *operator&() { return &obj; }
};

class Arb {};

void Func(Arb*) {}

int main()
{
Func(&Temp<Arb>());
}

--

Frederick Gotham
Jul 25 '06 #3

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

Similar topics

1
by: John Miles | last post by:
Hi -- This is a bit of an implementation-specific problem, but I'd like to post it here to see if there's a general answer within the auspices of the language. I'm developing a high(er)-level...
13
by: Neil Zanella | last post by:
Hello, I wonder whether anyone has ever come across the following g++ compiler error message. I don't recall ever seeing it before. I solved my problem but I am still not sure about what this...
5
by: Andy Buckley | last post by:
Hi, A friend and I have recently had trouble getting code to compile when using temporary objects in constructors. A minimal example is below: This code fragment is used to construct seven ROD...
5
by: White Wolf | last post by:
Hi, I would like to double check how long a temporary returned by a function lives? Suppose I have an instance of a class type C, which has a member function returning some sort of...
27
by: Daniel Vallstrom | last post by:
I'm having problems with inconsistent floating point behavior resulting in e.g. assert( x > 0.0 && putchar('\n') && x == 0.0 ); holding. (Actually, my problem is the dual one where I get...
8
by: Z D | last post by:
Hello, I'm having a strange problem that is probably due to my lack of understanding of how threading & COM Interop works in a WinForms.NET application. Here's the situation: I have a 3rd...
1
by: dirk van waes | last post by:
Hello everyone, Being complete newbie in asp.net I am trying to make an example which works with a very simple database. First I made my project in VS- vb.net, draging an oledbconnection and an...
32
by: Axel Bock | last post by:
Hi all, I am trying to get my head around what happens if I return a class object from a function. It seems C++ (MinGW) does not invoke the copy constructor if I do something like this: ...
0
by: gunimpi | last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431 ******************************************************** VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help wanted...
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
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
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.