Path: utzoo!utgpu!water!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!mailrus!ncar!oddjob!mimsy!chris From: chris@mimsy.UUCP (Chris Torek) Newsgroups: comp.lang.c Subject: sizes, bitfields, etc Message-ID: <12933@mimsy.UUCP> Date: 10 Aug 88 03:12:59 GMT References: <214@ISIDAPS5.UUCP> <9641@dartvax.Dartmouth.EDU> <62505@sun.uucp> <11794@steinmetz.ge.com> Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742 Lines: 39 >In article <1199@ficc.UUCP> peter@ficc.UUCP (Peter da Silva) writes: >>Not trying to start a war or anything, but how far do you really have >>to stretch the language to allow: >> int a:16; In article <11794@steinmetz.ge.com> davidsen@steinmetz.ge.com (William E. Davidsen Jr) answers: >I proposed something like this to X3J11 [but size in bytes] ... >The feeling was that it was (a) not really needed and (b) too much like >fortran. I like your idea better, but the few cases where you want exact >size rather than minimum size probably don't justify inclusion. >It would be nice some times to be able to specify a bit array .... >I would really like to see a "packed struct," also. This would be a >struct packed on byte boundaries without fill, no matter *how bad* the >code was to use them. I am not sure that ANY of these belong in C (nor that that any or all do not), but in some language(s) packed structures, bit arrays, and exact-bit-sized variables would be useful. If, however, you are going to provide structure packing, I suggest NOT restricting it to byte boundaries. If you need tight packing, the expense for getting at bit-fields that cross word boundaries is probably worth it. If you then can accept looser packing, all you need do is write (e.g.): ... { bits a:(ROUNDUP(3,BITS_PER_BYTE)); bits c:(ROUNDUP(11,BITS_PER_BYTE)); ... where ROUNDUP is a compile-time expression that rounds its first argument up to the nearest multiple of its second argument: /* nb. beware overflow in (x)+(y)-1 below */ #define ROUNDUP(x, y) (floor(((x) + (y) - 1) / (y)) * (y)) -- In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163) Domain: chris@mimsy.umd.edu Path: uunet!mimsy!chris