This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

size_t printf warnings and preprocessor


I would love to get size_t warnings for printf out of gcc.
I've already noticed that 3.0 is much better at following typeinfo than
2.95 used to.

I would like to have a switch such that 
size_t var;
printf(format, var);

invariably ends in an error, as there can't be a single format that works
with size_t.

Understandably, this warning ought to be tunable, as somebody may be 
playing macro-processor tricks to ensure the format does indeed match size_t
on the machine at hand.

Okay so far, I think I can write all this.

Now, for the next trick: since the new preprocessor is somewhat better 
integrated with gcc, would it be possible to pass string information
along.

Say, if you have a specific format specifier for size_t, say
FMT_SIZE_T (I think there's even such a specifier as part of C9X),
and the format used with printf is obtained through ansi string concatenation,
then all that would be needed would be to mark this string as special
(in the preprocessor) so that gcc knows better when to drop the warning.

It could either be achieved by passing stuff behind the scene, or
maybe emitting an extra attribute: (extends gcc grammar slightly ?) so that
one could mark substrings and such...

I haven't looked where ansi string folding occurs, but you could mark a
string as being `suitable for size_t' (say, 
#define FMT_SIZE_T "%lu" __attribute__((size_t_format))
and string concatenation would retain that property (possibly, each `folded'
string would have to keep a list of annotated strings around, so that
format checking could become much more precise.

In my opinion, this could become VERY useful with C9X...


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]