aph@redhat.com

Andrew Haley aph@redhat.com
Thu Sep 3 10:18:08 GMT 2020


On 02/09/2020 19:25, Joe Buehler wrote:
> Andrew Haley wrote:
>> On 27/08/2020 22:23, Joe Buehler via Gcc-help wrote:
>>
>>     temp.c: In function  main :
>>     temp.c:4:2: warning: asm operand 0 probably doesn t match constraints
>>       __asm__ volatile(".8byte %0\n\t" : : "i" ("message %s\n"));
>>       ^~~~~~~
>>     temp.c:4:2: error: impossible constraint in  asm
>>
>> I'd use the "S" constraint.
>
> Thanks that worked.
>
>>> I am unable to code something similar manually using inline asm because
>>> the string is a format string containing % characters, which inline asm
>>> will of course try to interpret. (Does gcc provide anything to escape %
>>> chars in a literal string?)
>>
>> "%%"
>
> The problem is that I have literal printf format strings in a
> multiplatform code base.  I need something like a gcc builtin to do
> the % doubling.
>
> #define X(fmt) asm ("lines " __builtin_escape(fmt) " more lines")

I'm not sure I really understand the problem. You only need the "%%"
if the "%" characters are in the actual asm string, not the parameter
passed, which can be any string. If you're assuming that it's possible
to create inline asm code portable across non-GCC compilers, then that
hasn't ever been so.

Having said that, I'm fairly sure that __builtin_escape() could be
written in C++. If you were feeling brave!

-- 
Andrew Haley  (he/him)
Java Platform Lead Engineer
Red Hat UK Ltd. <https://www.redhat.com>
https://keybase.io/andrewhaley
EAC8 43EB D3EF DB98 CC77 2FAD A5CD 6035 332F A671



More information about the Gcc-help mailing list