public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jonny Grant <jg@jguk.org>
To: Segher Boessenkool <segher@kernel.crashing.org>
Cc: Richard Earnshaw <Richard.Earnshaw@foss.arm.com>,
	gcc-help <gcc-help@gcc.gnu.org>
Subject: Re: Could __builtin_printf parameters be optimized when being compiled
Date: Thu, 16 Feb 2023 13:48:46 +0000	[thread overview]
Message-ID: <3567fe85-3f93-7ff4-bf47-fc7b61dbbc00@jguk.org> (raw)
In-Reply-To: <20230215154936.GG25951@gate.crashing.org>



On 15/02/2023 15:49, Segher Boessenkool wrote:
> On Wed, Feb 15, 2023 at 03:10:15PM +0000, Jonny Grant wrote:
>> On 15/02/2023 14:30, Richard Earnshaw wrote:
>>>> int main()
>>>> {
>>>>      __builtin_printf("file %s:%d", __FILE__, __LINE__);
>>>> }
> 
> Note that the format needs to end in "\n" if you want this to be
> converted to a puts() call.  Without it it strangely doesn't seem to
> be optimised, although fprintf() is converted to fwrite() in such cases.
> This could be done for printf() as well: you are guaranteed to have
> access to stdout as well, at least if you use printf() instead of the
> builtin (I'm not sure if we do then).
> 
>>> I guess it might be possible to handle cases where all the arguments are constant, but even that has its problems, eg:
>>>
>>> - can we guarantee identical output to the platform printf?
>>
>> That's a good question. I was using __builtin_printf so that should be GCC I expect.
> 
> Not every printf() implementation has exactly the same output in all
> cases.
> 
> Another practically important consideration is what it does to i18n.
> You really need to leave the format string unmodified for that to be
> able to work.
Thank you for your reply. i18n is a good point. At the moment I was just trying to get some strings for debugging in.

Kind regards
Jonny

      parent reply	other threads:[~2023-02-16 13:48 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-15 14:18 Jonny Grant
2023-02-15 14:30 ` Richard Earnshaw
2023-02-15 15:10   ` Jonny Grant
2023-02-15 15:27     ` Richard Earnshaw
2023-02-16 13:47       ` Jonny Grant
2023-02-15 15:49     ` Segher Boessenkool
2023-02-15 16:42       ` Richard Earnshaw
2023-02-16 13:48       ` Jonny Grant [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3567fe85-3f93-7ff4-bf47-fc7b61dbbc00@jguk.org \
    --to=jg@jguk.org \
    --cc=Richard.Earnshaw@foss.arm.com \
    --cc=gcc-help@gcc.gnu.org \
    --cc=segher@kernel.crashing.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).