parsing the format string at compile time...

John O'Brien jobrien at nixbur.UUCP
Wed Oct 11 07:45:35 AEST 1989


I'm looked a description of Modula-2 yesterday, and one of the things
that struck me was its lack of a general purpose I/O function.  Instead,
you have a collection of procedures which output one value of each type.
Thus, where you would say in C:

printf("This is an integer: %d\n", 6);

you would need three procedure calls in Mod-2:

writechar("This is an integer: ");
writeint(6);
writeln;

which is a real pain in the neck for writing report programs, but which
can be very fast, because the Modula-2 programmer is parsing the format
string manually, where the format string is parsed at run-time in the C
program.  For a more complicated example, the savings in time might be
pretty significant.  It seems to me that if the format string in the 
printf call is a constant (which it is most of the time), the compiler
should be able to parse the string at compile time, and turn the printf
call into something like the series of Modula-2 calls, with a correspond-
ing increase in efficiency.  Do C compilers do this?  Are there any prob-
lems with doing this?

				Enquiring Minds Want to Know!

#include "std_disclaimer.h"

"I Saw Elvis in a 386 Circuit Diagram!" -- coming soon to a newsstand near you!



More information about the Comp.lang.c mailing list