Getting format of arg_type

Manuel López-Ibáñez
Sun Apr 17 22:10:00 GMT 2016

On 15 April 2016 at 14:34, Prasad Ghangal <> wrote:
> Hi!
> Regarding PR64955, I was observing function format_type_warning() (in
> c-family/c-format.c), how can I get format specifier for arg_type?
> Say, if tree arg_type stores 'char', then how can I get its format i.e. 'c' ?

That information is in the various *_table that you can find near the
top of c-format.c. The types in the tables are defined by various
'#define T_*' in c-format.h. I wish the names were a bit more

As far as I know, there is no function that given a type, gives you
the most appropriate format. Writing such a function is the main
challenge in that PR. Basically you need to figure out what the
existing code is doing to find out, given a format such as 'c', that
the wanted_type is 'char', and reverse that logic. (There may be more
than one possible valid format given a type).

Moreover, the whole c-format.* is a very old piece of GCC. If you can
think about simplifications or additional comments that could help
people like you in understanding it, please do not hesitate to propose
patches in that direction. I don't think we even have a short
description on how to add new format specifiers or flags to the
tables. That would be extremely useful to add at the top of the file.



More information about the Gcc mailing list