Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Path: utzoo!mnetor!uunet!seismo!mcnc!gatech!bloom-beacon!think!ames!oliveb!sun!gorodish!guy
From: guy%gorodish@Sun.COM (Guy Harris)
Newsgroups: comp.bugs.4bsd,comp.unix.wizards
Subject: Re: 4.3BSD stdio.h - sprintf() definition
Message-ID: <23741@sun.uucp>
Date: Fri, 17-Jul-87 14:08:14 EDT
Article-I.D.: sun.23741
Posted: Fri Jul 17 14:08:14 1987
Date-Received: Sat, 18-Jul-87 16:47:16 EDT
References: <521@quacky.UUCP> <526@quacky.UUCP>
Sender: news@sun.uucp
Lines: 57
Xref: mnetor comp.bugs.4bsd:450 comp.unix.wizards:3287

> What my question is is why is it '#ifdef vax' and what isn't "vax"?
> In other words, is it this way because Sun and Gould and Pyramid
> and n other companies that wanted to be able to share the code
> decided to go with sprintf() returning an int?

We wanted to, but it caused too many problems.  I suspect that may be
why the #ifdef is there.

> Our BSD-derived system is not a Vax, so the compiler doesn't define
> "vax". Will my code (defined as the entire set of 4.3BSD commands
> that are not totally DEC hardware dependent) break if I remove
> the #ifdef?

Probably not.  It probably won't break if you leave it in, either;
programs that don't depend on that characteristic of "sprintf" will
get "lint" complaints, and programs that *do* depend on it will get
compile-time warnings.  There's really no point in using that
feature, so you might just want to change those programs not to do
so.

> Personally, I have a lot of problems with programs where people
> put in #ifdefs based on hardware types when the #ifdef should
> be based on something else. A good example (sorry Doug) is when
> I ported the BRL System V package to the MIPS system and found
> that some of the #ifdefs for "vax" applied (overall system
> architecture, usually vs. pdp11) and some didn't (byte order,
> in particular).

The trouble here is that there is no system-supplied predicate for
testing the byte-order of a particular machine, so those people
didn't really have any choice other than to require anybody doing the
porting to set up the Makefile or some include file to specify the
byte sex.  There *should* either be a predicate built into the C
preprocessor/compiler or a #define constant in some system include
file; the trouble with putting in

	#if vax || iAPX286 || i386 ...

or

	#if mc68000 || m68k || sparc ...

is that 1) there's no guarantee that there will be a unique #define
for a particular machine (consider "mc68000" vs. "m68k") and 2) it
doesn't help when a new machine comes along.  (I don't even know what
the magic predefine is for the NS32K series, or even if everybody
uses the same one, so I didn't put it in up there; I don't know if
there *is* one for the WE32K series - AT&T seems to use stuff like

	#if u3b20 || u3b2 || u3b5 || u3b15 || ...

but enumerating all the 3Bs seems like a silly way of defining the
set of machines using the WE32K (unless, of course, that set stops
growing at some point, which is certainly possible).)
	Guy Harris
	{ihnp4, decvax, seismo, decwrl, ...}!sun!guy
	guy@sun.com