Path: utzoo!attcan!uunet!ncrlnk!ncrcae!hubcap!gatech!uflorida!haven!adm!smoke!gwyn From: gwyn@smoke.BRL.MIL (Doug Gwyn ) Newsgroups: comp.lang.c Subject: Re: sprintf(3s) query Message-ID: <9205@smoke.BRL.MIL> Date: 16 Dec 88 20:46:02 GMT References: <1102@entropy.ms.washington.edu> <8131@ihlpl.ATT.COM> <865@quintus.UUCP> <9181@smoke.BRL.MIL> <878@quintus.UUCP> Reply-To: gwyn@brl.arpa (Doug Gwyn (VLD/VMB) ) Organization: Ballistic Research Lab (BRL), APG, MD. Lines: 34 In article <878@quintus.UUCP> ok@quintus.UUCP (Richard A. O'Keefe) writes: -In article <9181@smoke.BRL.MIL> gwyn@brl.arpa (Doug Gwyn (VLD/VMB) ) writes: ->#ifdef vax ->char *sprintf(); /* too painful to do right */ ->#endif ->Note that Sun MUST have changed this in order for it to apply to ->their (definitely non-VAX) machines. -In point of fact, at least as of SunOS 3.2, they DIDN'T. -So much for "MUST". The effect is that in SunOS, if you wanted the -buffer pointer, you had to explicitly declare sprintf() yourself. I thought the poster who originated this discussion said that his version of SunOS had done this. I'm still covered by the "in order for" clause in what I said. ->I hope by now all the BSD code that depends on the value of ->sprintf() being anything in particular has been changed to use ->some other method. Usually, something like -> buf[0] = '\0'; -> (void)sprintf(buf, fmt, args); -> if (buf[0] == '\0') -> /* error */ ->is sufficient (it works with both definitions of sprintf()). -Except that it doesn't work with either. Consider - sprintf("%.*s", len, ptr); -when len happens to be 0. By the way, what _are_ the output error -conditions that *printf() can detect other than by crashing? Again, I said "Usually, ..." which implies "not always". The vast majority of sprintf() usage can correctly be changed to follow my suggestion. I note that you offered no alternative. There are several possible errors other than I/O errors. Think hard enough and you should be able to imagine at least one.