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