Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!mcnc!rti!xyzzy!tiktok!meissner From: meissner@tiktok.dg.com (Michael Meissner) Newsgroups: comp.lang.c Subject: Re: parsing the format string at compile time... Message-ID: <1856@xyzzy.UUCP> Date: 15 Oct 89 18:06:49 GMT References: <705@nixbur.UUCP> <6737@hubcap.clemson.edu> Sender: usenet@xyzzy.UUCP Reply-To: meissner@tiktok.UUCP (Michael Meissner) Distribution: usa Organization: Data General (Languages @ Research Triangle Park, NC.) Lines: 39 In article <6737@hubcap.clemson.edu> drcook@hubcap.clemson.edu (david richard cook) writes: | From article <705@nixbur.UUCP>, by jobrien@nixbur.UUCP (John O'Brien): | > 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? | | If C did allow this, it would not be C. The compiler knows | nothing about any functions, including I/O. Wrong. The ANSI standard gives explicit license for implementations to 'know' about any of the standard functions in section 4. Nothing requires that a user call to 'printf' call an actual routine printf. All that is required, besides getting the corect result, is that an implementation not evaluate arguments more than once (except for grandfathering putc/getc/putchar/getchar, and possibly a few others that have historically been macros), and that taking the address of the function work. Granted I don't know about any compilers that currently do this with printf, but there are compilers which will do special things for certain library routines (typically math or memory/string copies and compares). For example, the Data General MV C compiler has quite a few routines that are builtin, such as memcpy, strcpy, memcmp, strcmp, abs, fabs, sin, etc. Also, the GNU C compiler has support for builtin functions, though at present there aren't that many (abs, labs, fabs, alloca, etc.). | Some new compilers may be | able to this, though I do not know of any, by using the #pragma | preprocesser directive to declare certain functions as builtin. The | use of #pragma is left up to the compiler implementation and not C. | If an ANSI C implementation does not understand what the #pragma | directive is trying to accomplish, it will simply ignore it. Even though I originally voted for pragma in the ANSI committee, I feel that the current semantics are a botch.... Michael Meissner, Data General. If compiles where much Uucp: ...!mcnc!rti!xyzzy!meissner faster, when would we Internet: meissner@dg-rtp.DG.COM have time for netnews?