473,657 Members | 2,507 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2390
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_ca st<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
2598
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 scripting language designed explicitly to complement C++. One of the language's features is the ability to pass "out" parameters to an MSVC __cdecl function by reference. After the C++ function returns, but before popping the parameters from the
13
1862
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 message is all about. Any ideas? error: invalid initialization of non-const reference of
5
1502
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 objects and run their doSomething() method (which is trivial). As far as we can tell, all seven methods should successfully construct a ROD object using temporary objects as constructor parameters, but using
5
1690
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 wrapper-decorator by value - thereby creating an unnamed temporary. Assuming I start using the temporary (by calling its members) in the same expression, can I assume that it will live long enough to serve those calls?
27
3824
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 failed assertions for assertions that at first thought ought to hold, but that's not important.) At the end is a full program containing the above seemingly
8
8192
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 party COM component that takes about 5 seconds to run one of its functions (Network IO bound call). Since I dont want my GUI to freeze
1
1431
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 oledbdataadapter from the toolbox into my form. Everything worked fine on my local computer. I was able to search, update, delete and insert into my klanten.mdb database.
32
2196
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: SomeObj foo() { SomeObj X;
0
5558
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 ******************************************************** For this teeny job, please refer to: http://feeds.reddit.com/feed/8fu/?o=25
0
8425
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8326
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
7355
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6177
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5647
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4173
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2745
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1973
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1736
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.