statement expressions and extended asm bug?

Jamie Lokier jamie@shareable.org
Mon Mar 15 20:25:00 GMT 2004


Nathan Sidwell wrote:
> inline int foo (int arg_)
> {
>   int result __asm("d0");
>   int arg __asm("d1"); // for sake of argument
> 
>   arg = arg_;
>   asm ("call whereever": "=r(result)" :"r(arg)" : ...);
> 
>   return result;
> }
> 
> This is subtly different from the statement expression form, because
> the result of a C statement expression can be an lvalue, whereas here
> it is an rvalue. (in g++, statement expressions always produce a result
> 'as-if' by 'return').

More to the point, calling the foo(arg) above from different function
arguments isn't a sequence-point violation, unlike calling the
statement-expressions.

    function(foo(arg1), foo(arg2));

could evaluate the two calls to foo() in either order, but it must
finish one completely before the other.

Perhaps this is a flaw in GCC's implementation of
statement-expression, because s-e is intended for use in macros
function-like macros -- whose callers don't know they are calling a
macro.

-- Jamie



More information about the Gcc mailing list