On Tuesday 17 August 2010 16:15:40 you wrote: > Job Noorman <jobnoorman@xxxxxxxxx> writes: > > Consider the following code snippet: > > struct Foo > > { > > > > void foobar() {} > > > > }; > > > > typedef void (*plain_foobar_t)(Foo*); > > > > void test() > > { > > > > asm("push %0;" > > > > : "i"((plain_foobar_t)&Foo::foobar)); > > > > } > > > > int main(){} > > > > If I compile this with > > > > g++ -Wno-pmf-conversions main.cpp > > > > I get the following; > > > > main.cpp: In function ‘void test()’: > > main.cpp:12: warning: asm operand 0 probably doesn’t match > > constraints main.cpp:12: error: impossible constraint in ‘asm’ > > I would not expect this kind of thing to work when not optimizing. You > are requiring the compiler to see that the value is an integer constant, > which the compiler can't reliably do when not optimizing. > > It should work reliably with or without optimization if you use an "r" > constraint, though of course that will introduce an additional > instruction. > > Ian When I use the "r" constraint, it indeed works and GCC emits the following code: movl $_ZN3Foo6foobarEv, %eax push %eax; What I find strange about this is that GCC has converted "(plain_foobar_t)&Foo::foobar" in a constant value ($_ZN3Foo6foobarEv) without using optimizations. So why can't it do the same when using the "i" constraint? Job