18 Sep 2000 jsm28   » (Master)

I'm in the process of reorganising GCC's code for checking printf, scanf and strftime formats.

Originally the code used a flag to indicate whether a function was printf-like or scanf-like. Then more and more format features from X/Open, various extensions and C99 were added, strftime format support was added to help detect Y2K problems, and the amount of ad hoc conditionals in the code for particular cases steadily went up; though the details of what type is expected by each combination of a conversion specifier (e.g. d) and a length modifier (e.g. l) were stored in a table (in this example showing that printf %ld expects a long argument), as were details of the acceptable flags on each conversion, more and more other information went into ad hoc code, which was full of bugs, especially in the details of what GCC accepted with each standard version selected and -pedantic.

After reorganising and rewriting much of the code, it should now follow C99 correctly, except for lack of support for the j length modifier (intmax_t and uintmax_t), which needs work elsewhere in GCC and a solution to the question of whether GCC or glibc should be providing <stdint.h>. For example, with GCC 3.0 you will be able to use %zu formats for size_t values and so get rid of ugly casts to unsigned long that were previously needed for portable code (as long as you don't need to support older systems with pre-C99 libraries that don't understand %zu; glibc 2.1 is OK though there are a few C99 format features it lacks, and glibc 2.2 will have an almost complete implementation of the whole C99 standard library). Details of the standards versions in which features appeared are now stored in data; all X/Open extensions and most glibc extensions are supported. The next stage is to move details of the flags supported by each format type into data as well; the eventual target is to allow a program to specify the format rules for its own printf-like functions. (For example, a while ago on linux-kernel it was suggested to add format extensions to format IP addresses with printk, but GCC couldn't check such extensions. FreeBSD, with much closer control over the GCC used, has such extensions and modifies GCC to add hardcoded support for them.)

Latest blog entries     Older blog entries

New Advogato Features

New HTML Parser: The long-awaited libxml2 based HTML parser code is live. It needs further work but already handles most markup better than the original parser.

Keep up with the latest Advogato features by reading the Advogato status blog.

If you're a C programmer with some spare time, take a look at the mod_virgule project page and help us with one of the tasks on the ToDo list!