* Ian Lance Taylor: > Florian Weimer <[EMAIL PROTECTED]> writes: > >> * Ian Lance Taylor: >> >> > I haven't tried to flesh this out any further. I'd be curious to hear >> > how people react to it. >> >> Can't we just use some inline function written in plain C to check the >> arguments and execute it at compile time using constant folding etc.? > > I don't really see how that could work and still do what we want it to > do. Could you give an example of what it would look like?
If I understand your %A/%B example correctly, it would look like this: /* FORMAT is the complete format string, POS the offset of the current % directive. Returns a C type specifcier as a string. NULL means: do not consume any argument */ static inline const char * printf_checker_bfd (const char *format, size_t pos) { if (strncmp (format + pos, "%A", 2) == 0) { if (pos != 0) { __builtin_warn ("`%A' must occur at the start of the format string"); return "void *"; // accept anything } return "asection *"; } if (strncmp (format + pos, "%B", 2) == 0) { if (pos != 0) { __builtin_warn ("`%B' must occur at the start of the format string"); return "void *"; // accept anything } return "bfd *"; } return __builtin_printf_checker (format, pos); // handle printf format string } #pragma GCC format "bfd" "invoke printf_checker_bfd" The interface still needs some polishing; it might be desirable to be able to pass along some kind of flag. Perhaps it's more obvious to express the scanning loop in the checking code and explicitly compare the type using some builtin, but this is probably even more challenging on the optimiziers.