Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!wuarchive!brutus.cs.uiuc.edu!usc!bloom-beacon!spdcc!merk!alliant!linus!nixbur!jobrien From: jobrien@nixbur.UUCP (John O'Brien) Newsgroups: comp.lang.c Subject: parsing the format string at compile time... Keywords: format printf parsing modula-2 Message-ID: <705@nixbur.UUCP> Date: 10 Oct 89 21:45:35 GMT Distribution: usa Organization: Nixdorf Computer Engineering Corporation, Burlington, MA Lines: 29 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!