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