From owner-freebsd-hackers Sun Apr 6 05:22:41 1997 Return-Path: Received: (from root@localhost) by freefall.freebsd.org (8.8.5/8.8.5) id FAA18928 for hackers-outgoing; Sun, 6 Apr 1997 05:22:41 -0700 (PDT) Received: from sax.sax.de (sax.sax.de [193.175.26.33]) by freefall.freebsd.org (8.8.5/8.8.5) with SMTP id FAA18919 for ; Sun, 6 Apr 1997 05:22:35 -0700 (PDT) Received: (from uucp@localhost) by sax.sax.de (8.6.12/8.6.12-s1) with UUCP id OAA05165 for freebsd-hackers@freebsd.org; Sun, 6 Apr 1997 14:22:23 +0200 Received: (from j@localhost) by uriah.heep.sax.de (8.8.5/8.8.5) id OAA17155; Sun, 6 Apr 1997 14:09:09 +0200 (MET DST) Message-ID: <19970406140909.UB47399@uriah.heep.sax.de> Date: Sun, 6 Apr 1997 14:09:09 +0200 From: j@uriah.heep.sax.de (J Wunsch) To: freebsd-hackers@freebsd.org Subject: Re: How to declare device driver variables and data structures ? References: X-Mailer: Mutt 0.60_p2-3,5,8-9 Mime-Version: 1.0 X-Phone: +49-351-2012 669 X-PGP-Fingerprint: DC 47 E6 E4 FF A6 E9 8F 93 21 E0 7D F9 12 D6 4E Reply-To: joerg_wunsch@uriah.heep.sax.de (Joerg Wunsch) In-Reply-To: ; from Hellmuth Michaelis on Apr 6, 1997 12:04:01 +0200 Sender: owner-hackers@freebsd.org X-Loop: FreeBSD.org Precedence: bulk As Hellmuth Michaelis wrote: > i.e. if i know a variable can only have values 0 ... 32, shall i make it > an unsigned char ? Is it slower to make such variables an unsigned int > or an unsigned short ? What are the space vs. speed considerations ? You should probably only use shorter values than plain int or unsigned if either the hardware enforces a particular size (since it's a mirror of a hardware register or such), or if you pack a bunch of them beneath, and they are static/extern/bss. For automatic variables, i think it's better to stick with the default size for your machine. I'm not sure, but if it has an effect at all, restraining the size will make the access slower. > another i.e. for boolean variables, is it better to make them chars, shorts > or ints ? signed or unsigned ? int's, unless you have many of them in static storage. But then, you want to make them flag bits, and store them temporarily in ints locally if you need them a lot. > What is the speed of unsigned variables vs. signed variables ? No difference, at least not on the ix86. > What is with future ports to other architectures ? Do you wanna predict the future? :-) Generally, using variables of a non-default size is likely to make the code slower. Other machines have a lot more of registers, so there's nothing wrong to store temp values in registers. Don't use `register' declarations, the compiler is usually better in knowing what should go into a register. > How does this all apply to variables being part of structures ? Alignment problems... see also style(9). -- cheers, J"org joerg_wunsch@uriah.heep.sax.de -- http://www.sax.de/~joerg/ -- NIC: JW11-RIPE Never trust an operating system you don't have sources for. ;-)