Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!sol.ctr.columbia.edu!ira.uka.de!smurf!artcom0!hb.maus.de!ms.maus.de!Kai_Henningsen From: Kai_Henningsen@ms.maus.de (Kai Henningsen) Newsgroups: comp.lang.c Subject: Re: 64 bit architectures and C Message-ID: <15074@ms.maus.de> Date: 7 May 91 11:49:00 GMT Article-I.D.: ms.15074 Distribution: world,comp Organization: Maus Mailbox Netz - UUCP-Gateway Bremen Lines: 48 warren.a.montgomery warren @ cbnewsh.att.com schrieb am 29.04.1991, 12:02 ww>There are lots of ways a programmer may want to declare an integer: ww> ww>1 Any convenient and reasonable size. ww> ww>2 Any convenient size large enough to represent X. ww> ww>3 The smallest convenient size large enough to represent X. ww> ww>4 Exactly Y bits or bytes long. ww> ww>5 Exactly the same size as datatype Z ww>but these will do for a start. How are things like this best ww>expressed in C or C++? Do other languages provide better overall solutions? Well, I'd say there is only one way, if you program for portability. First, use int (and char) for (1). Second, whenever you need something else, typedef (in a central header file) a type for it, using a good-to-remember name, AND COMMENT WHAT EXACTLY YOU TRY TO DO at the same place, so the guy doing the port will know what to substitute. Try not to rely on external data formats, but if you do, encapsulate transitions between internal and external representations (even if identical) in functions, AND MARK THEM CLEARLY, so the porter will know where to look in case of odd-sized ints or different byte sex. And while we're at it, DON'T ASSUME YOU HAVE ASCII! As for other solutions, the one I use somewhat often is Pascal. There, you can specify exactly which values you expect to store in a type, that is, you can define a type for month values like this: TYPE Month = 1 .. 12; This adds the added benefit that the compiler can check that you really use only those values, thus catching those annoying bugs ... On the other hand, for packing, you can only tell the compiler that you want him to pack this data structure - not how to do it. Bit fields are somewhat better ... MfG Kai